<html><head><title>/Users/Alexander/SandBox/nwscode/nwscode/pydatetime.py</title>
        <script type="text/javascript"><!--
        
function show_line_range() {
    var href = document.location.href;
    if (href.indexOf('?') == -1) {
        return;
    }
    var qs = href.substring(href.indexOf('?')+1);
    if (qs.indexOf('#') >= 0) {
        qs = qs.substring(0, qs.indexOf('#'));
    }
    var first = qs.match(/f=(\d+)/)[1];
    var last = qs.match(/l=(\d+)/)[1];
    if (! first || ! last) {
        return;
    }
    var anchors = document.getElementsByTagName('A');
    var container = document.createElement('DIV');
    container.className = 'highlighted';
    var children = [];
    var start = null;
    var parent = null;
    var highlight = false;
    for (var i = 0; i < anchors.length; i++) {
        var el = anchors[i];
        if (el.getAttribute('name') == first) {
            start = el.previousSibling;
            parent = el.parentNode;
            highlight = true;
        }
        if (el.getAttribute('name') == last) {
            break;
        }
        if (highlight) {
            children[children.length] = el;
            el = el.nextSibling;
            while (el && el.tagName != 'A') {
                children[children.length] = el;
                el = el.nextSibling;
            }
        }
    }
    for (i=0; i<children.length; i++) {
        container.appendChild(children[i]);
    }
    if (start) {
        start.parentNode.insertBefore(container, start.nextSibling);
    } else {
        parent.insertBefore(container, parent.childNodes[0]);
    }
}

        // --></script>
        <style>
        div.python {
          color: #333
        }
        div.python a.lnum {
          color: #555;
          background-color: #eee;
          border-right: 1px solid #999;
          padding-right: 2px;
          margin-right: 4px;
        }
        div.python span.comment { color: #933 }
        div.python span.keyword { color: #a3e; font-weight: bold  }
        div.python span.op { color: #c96 }
        div.python span.string { color: #6a6 }
        div.python span.name { }
        div.python span.text { color: #333 }
        div.highlighted { background-color: #ff9; border: 1px solid #009 }
        </style></head><body onload="show_line_range()"><div class="python"><code><a class="lnum" href="#1" name="1">0001</a><span class="string">"""Concrete&#0160;date/time&#0160;and&#0160;related&#0160;types&#0160;--&#0160;prototype&#0160;implemented&#0160;in&#0160;Python.</span><br />
<a class="lnum" href="#2" name="2">0002</a><span class="string"></span><br />
<a class="lnum" href="#3" name="3">0003</a><span class="string">See&#0160;http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage</span><br />
<a class="lnum" href="#4" name="4">0004</a><span class="string"></span><br />
<a class="lnum" href="#5" name="5">0005</a><span class="string">See&#0160;also&#0160;http://dir.yahoo.com/Reference/calendars/</span><br />
<a class="lnum" href="#6" name="6">0006</a><span class="string"></span><br />
<a class="lnum" href="#7" name="7">0007</a><span class="string">For&#0160;a&#0160;primer&#0160;on&#0160;DST,&#0160;including&#0160;many&#0160;current&#0160;DST&#0160;rules,&#0160;see</span><br />
<a class="lnum" href="#8" name="8">0008</a><span class="string">http://webexhibits.org/daylightsaving/</span><br />
<a class="lnum" href="#9" name="9">0009</a><span class="string"></span><br />
<a class="lnum" href="#10" name="10">0010</a><span class="string">For&#0160;more&#0160;about&#0160;DST&#0160;than&#0160;you&#0160;ever&#0160;wanted&#0160;to&#0160;know,&#0160;see</span><br />
<a class="lnum" href="#11" name="11">0011</a><span class="string">ftp://elsie.nci.nih.gov/pub/</span><br />
<a class="lnum" href="#12" name="12">0012</a><span class="string"></span><br />
<a class="lnum" href="#13" name="13">0013</a><span class="string">Sources&#0160;for&#0160;time&#0160;zone&#0160;and&#0160;DST&#0160;data:&#0160;http://www.twinsun.com/tz/tz-link.htm</span><br />
<a class="lnum" href="#14" name="14">0014</a><span class="string"></span><br />
<a class="lnum" href="#15" name="15">0015</a><span class="string">This&#0160;was&#0160;originally&#0160;copied&#0160;from&#0160;the&#0160;sandbox&#0160;of&#0160;the&#0160;CPython&#0160;CVS&#0160;repository.</span><br />
<a class="lnum" href="#16" name="16">0016</a><span class="string">Thanks&#0160;to&#0160;Tim&#0160;Peters&#0160;for&#0160;suggesting&#0160;using&#0160;it.&#0160;</span><br />
<a class="lnum" href="#17" name="17">0017</a><span class="string">"""</span><br />
<a class="lnum" href="#18" name="18">0018</a><br />
<a class="lnum" href="#19" name="19">0019</a><span class="keyword">import</span>&#0160;<span class="name">time</span>&#0160;<span class="name">as</span>&#0160;<span class="name">_time</span><br />
<a class="lnum" href="#20" name="20">0020</a><span class="keyword">import</span>&#0160;<span class="name">math</span>&#0160;<span class="name">as</span>&#0160;<span class="name">_math</span><br />
<a class="lnum" href="#21" name="21">0021</a><br />
<a class="lnum" href="#22" name="22">0022</a><span class="name">MINYEAR</span>&#0160;<span class="op">=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#23" name="23">0023</a><span class="name">MAXYEAR</span>&#0160;<span class="op">=</span>&#0160;<span class="number">9999</span><br />
<a class="lnum" href="#24" name="24">0024</a><br />
<a class="lnum" href="#25" name="25">0025</a><span class="comment">#&#0160;Utility&#0160;functions,&#0160;adapted&#0160;from&#0160;Python's&#0160;Demo/classes/Dates.py,&#0160;which</span><br />
<a class="lnum" href="#26" name="26">0026</a><span class="comment"></span><span class="comment">#&#0160;also&#0160;assumes&#0160;the&#0160;current&#0160;Gregorian&#0160;calendar&#0160;indefinitely&#0160;extended&#0160;in</span><br />
<a class="lnum" href="#27" name="27">0027</a><span class="comment"></span><span class="comment">#&#0160;both&#0160;directions.&#0160;&#0160;Difference:&#0160;&#0160;Dates.py&#0160;calls&#0160;January&#0160;1&#0160;of&#0160;year&#0160;0&#0160;day</span><br />
<a class="lnum" href="#28" name="28">0028</a><span class="comment"></span><span class="comment">#&#0160;number&#0160;1.&#0160;&#0160;The&#0160;code&#0160;here&#0160;calls&#0160;January&#0160;1&#0160;of&#0160;year&#0160;1&#0160;day&#0160;number&#0160;1.&#0160;&#0160;This&#0160;is</span><br />
<a class="lnum" href="#29" name="29">0029</a><span class="comment"></span><span class="comment">#&#0160;to&#0160;match&#0160;the&#0160;definition&#0160;of&#0160;the&#0160;"proleptic&#0160;Gregorian"&#0160;calendar&#0160;in&#0160;Dershowitz</span><br />
<a class="lnum" href="#30" name="30">0030</a><span class="comment"></span><span class="comment">#&#0160;and&#0160;Reingold's&#0160;"Calendrical&#0160;Calculations",&#0160;where&#0160;it's&#0160;the&#0160;base&#0160;calendar</span><br />
<a class="lnum" href="#31" name="31">0031</a><span class="comment"></span><span class="comment">#&#0160;for&#0160;all&#0160;computations.&#0160;&#0160;See&#0160;the&#0160;book&#0160;for&#0160;algorithms&#0160;for&#0160;converting&#0160;between</span><br />
<a class="lnum" href="#32" name="32">0032</a><span class="comment"></span><span class="comment">#&#0160;proleptic&#0160;Gregorian&#0160;ordinals&#0160;and&#0160;many&#0160;other&#0160;calendar&#0160;systems.</span><br />
<a class="lnum" href="#33" name="33">0033</a><span class="comment"></span><br />
<a class="lnum" href="#34" name="34">0034</a><span class="name">_DAYS_IN_MONTH</span>&#0160;<span class="op">=</span>&#0160;<span class="op">[</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">28</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">30</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">30</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">30</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">30</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">]</span><br />
<a class="lnum" href="#35" name="35">0035</a><br />
<a class="lnum" href="#36" name="36">0036</a><span class="name">_DAYS_BEFORE_MONTH</span>&#0160;<span class="op">=</span>&#0160;<span class="op">[</span><span class="name">None</span><span class="op">]</span><br />
<a class="lnum" href="#37" name="37">0037</a><span class="name">dbm</span>&#0160;<span class="op">=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#38" name="38">0038</a><span class="keyword">for</span>&#0160;<span class="name">dim</span>&#0160;<span class="keyword">in</span>&#0160;<span class="name">_DAYS_IN_MONTH</span><span class="op">[</span><span class="number">1</span><span class="op">:</span><span class="op">]</span><span class="op">:</span><br />
<a class="lnum" href="#39" name="39">0039</a>&#0160;&#0160;&#0160;&#0160;<span class="name">_DAYS_BEFORE_MONTH</span><span class="op">.</span><span class="name">append</span><span class="op">(</span><span class="name">dbm</span><span class="op">)</span><br />
<a class="lnum" href="#40" name="40">0040</a>&#0160;&#0160;&#0160;&#0160;<span class="name">dbm</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">dim</span><br />
<a class="lnum" href="#41" name="41">0041</a><span class="keyword">del</span>&#0160;<span class="name">dbm</span><span class="op">,</span>&#0160;<span class="name">dim</span><br />
<a class="lnum" href="#42" name="42">0042</a><br />
<a class="lnum" href="#43" name="43">0043</a><span class="keyword">def</span>&#0160;<span class="name">_is_leap</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#44" name="44">0044</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"year&#0160;-&gt;&#0160;1&#0160;if&#0160;leap&#0160;year,&#0160;else&#0160;0."</span><br />
<a class="lnum" href="#45" name="45">0045</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">year</span>&#0160;<span class="op">%</span>&#0160;<span class="number">4</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span>&#0160;<span class="keyword">and</span>&#0160;<span class="op">(</span><span class="name">year</span>&#0160;<span class="op">%</span>&#0160;<span class="number">100</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">year</span>&#0160;<span class="op">%</span>&#0160;<span class="number">400</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><span class="op">)</span><br />
<a class="lnum" href="#46" name="46">0046</a><br />
<a class="lnum" href="#47" name="47">0047</a><span class="keyword">def</span>&#0160;<span class="name">_days_in_year</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#48" name="48">0048</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"year&#0160;-&gt;&#0160;number&#0160;of&#0160;days&#0160;in&#0160;year&#0160;(366&#0160;if&#0160;a&#0160;leap&#0160;year,&#0160;else&#0160;365)."</span><br />
<a class="lnum" href="#49" name="49">0049</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="number">365</span>&#0160;<span class="op">+</span>&#0160;<span class="name">_is_leap</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#50" name="50">0050</a><br />
<a class="lnum" href="#51" name="51">0051</a><span class="keyword">def</span>&#0160;<span class="name">_days_before_year</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#52" name="52">0052</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"year&#0160;-&gt;&#0160;number&#0160;of&#0160;days&#0160;before&#0160;January&#0160;1st&#0160;of&#0160;year."</span><br />
<a class="lnum" href="#53" name="53">0053</a>&#0160;&#0160;&#0160;&#0160;<span class="name">y</span>&#0160;<span class="op">=</span>&#0160;<span class="name">year</span>&#0160;<span class="op">-</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#54" name="54">0054</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">y</span><span class="op">*</span><span class="number">365</span>&#0160;<span class="op">+</span>&#0160;<span class="name">y</span><span class="op">//</span><span class="number">4</span>&#0160;<span class="op">-</span>&#0160;<span class="name">y</span><span class="op">//</span><span class="number">100</span>&#0160;<span class="op">+</span>&#0160;<span class="name">y</span><span class="op">//</span><span class="number">400</span><br />
<a class="lnum" href="#55" name="55">0055</a><br />
<a class="lnum" href="#56" name="56">0056</a><span class="keyword">def</span>&#0160;<span class="name">_days_in_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#57" name="57">0057</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"year,&#0160;month&#0160;-&gt;&#0160;number&#0160;of&#0160;days&#0160;in&#0160;that&#0160;month&#0160;in&#0160;that&#0160;year."</span><br />
<a class="lnum" href="#58" name="58">0058</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">12</span><span class="op">,</span>&#0160;<span class="name">month</span><br />
<a class="lnum" href="#59" name="59">0059</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">month</span>&#0160;<span class="op">==</span>&#0160;<span class="number">2</span>&#0160;<span class="keyword">and</span>&#0160;<span class="name">_is_leap</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#60" name="60">0060</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="number">29</span><br />
<a class="lnum" href="#61" name="61">0061</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_DAYS_IN_MONTH</span><span class="op">[</span><span class="name">month</span><span class="op">]</span><br />
<a class="lnum" href="#62" name="62">0062</a><br />
<a class="lnum" href="#63" name="63">0063</a><span class="keyword">def</span>&#0160;<span class="name">_days_before_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#64" name="64">0064</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"year,&#0160;month&#0160;-&gt;&#0160;number&#0160;of&#0160;days&#0160;in&#0160;year&#0160;preceeding&#0160;first&#0160;day&#0160;of&#0160;month."</span><br />
<a class="lnum" href="#65" name="65">0065</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">12</span><span class="op">:</span><br />
<a class="lnum" href="#66" name="66">0066</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'month&#0160;must&#0160;be&#0160;in&#0160;1..12'</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#67" name="67">0067</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_DAYS_BEFORE_MONTH</span><span class="op">[</span><span class="name">month</span><span class="op">]</span>&#0160;<span class="op">+</span>&#0160;<span class="op">(</span><span class="name">month</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">2</span>&#0160;<span class="keyword">and</span>&#0160;<span class="name">_is_leap</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#68" name="68">0068</a><br />
<a class="lnum" href="#69" name="69">0069</a><span class="keyword">def</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#70" name="70">0070</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"year,&#0160;month,&#0160;day&#0160;-&gt;&#0160;ordinal,&#0160;considering&#0160;01-Jan-0001&#0160;as&#0160;day&#0160;1."</span><br />
<a class="lnum" href="#71" name="71">0071</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">12</span><span class="op">:</span><br />
<a class="lnum" href="#72" name="72">0072</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'month&#0160;must&#0160;be&#0160;in&#0160;1..12'</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#73" name="73">0073</a>&#0160;&#0160;&#0160;&#0160;<span class="name">dim</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_in_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#74" name="74">0074</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">day</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">dim</span><span class="op">:</span><br />
<a class="lnum" href="#75" name="75">0075</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'day&#0160;must&#0160;be&#0160;in&#0160;1..%d'</span>&#0160;<span class="op">%</span>&#0160;<span class="name">dim</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#76" name="76">0076</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">_days_before_year</span><span class="op">(</span><span class="name">year</span><span class="op">)</span>&#0160;<span class="op">+</span><br />
<a class="lnum" href="#77" name="77">0077</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_days_before_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span>&#0160;<span class="op">+</span><br />
<a class="lnum" href="#78" name="78">0078</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#79" name="79">0079</a><br />
<a class="lnum" href="#80" name="80">0080</a><span class="name">_DI400Y</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_before_year</span><span class="op">(</span><span class="number">401</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;number&#0160;of&#0160;days&#0160;in&#0160;400&#0160;years</span><br />
<a class="lnum" href="#81" name="81">0081</a><span class="name">_DI100Y</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_before_year</span><span class="op">(</span><span class="number">101</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;"&#0160;100&#0160;&#0160;&#0160;"</span><br />
<a class="lnum" href="#82" name="82">0082</a><span class="name">_DI4Y</span>&#0160;&#0160;&#0160;<span class="op">=</span>&#0160;<span class="name">_days_before_year</span><span class="op">(</span><span class="number">5</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;"&#0160;&#0160;&#0160;4&#0160;&#0160;&#0160;"</span><br />
<a class="lnum" href="#83" name="83">0083</a><br />
<a class="lnum" href="#84" name="84">0084</a><span class="comment">#&#0160;A&#0160;4-year&#0160;cycle&#0160;has&#0160;an&#0160;extra&#0160;leap&#0160;day&#0160;over&#0160;what&#0160;we'd&#0160;get&#0160;from&#0160;pasting</span><br />
<a class="lnum" href="#85" name="85">0085</a><span class="comment"></span><span class="comment">#&#0160;together&#0160;4&#0160;single&#0160;years.</span><br />
<a class="lnum" href="#86" name="86">0086</a><span class="comment"></span><span class="keyword">assert</span>&#0160;<span class="name">_DI4Y</span>&#0160;<span class="op">==</span>&#0160;<span class="number">4</span>&#0160;<span class="op">*</span>&#0160;<span class="number">365</span>&#0160;<span class="op">+</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#87" name="87">0087</a><br />
<a class="lnum" href="#88" name="88">0088</a><span class="comment">#&#0160;Similarly,&#0160;a&#0160;400-year&#0160;cycle&#0160;has&#0160;an&#0160;extra&#0160;leap&#0160;day&#0160;over&#0160;what&#0160;we'd&#0160;get&#0160;from</span><br />
<a class="lnum" href="#89" name="89">0089</a><span class="comment"></span><span class="comment">#&#0160;pasting&#0160;together&#0160;4&#0160;100-year&#0160;cycles.</span><br />
<a class="lnum" href="#90" name="90">0090</a><span class="comment"></span><span class="keyword">assert</span>&#0160;<span class="name">_DI400Y</span>&#0160;<span class="op">==</span>&#0160;<span class="number">4</span>&#0160;<span class="op">*</span>&#0160;<span class="name">_DI100Y</span>&#0160;<span class="op">+</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#91" name="91">0091</a><br />
<a class="lnum" href="#92" name="92">0092</a><span class="comment">#&#0160;OTOH,&#0160;a&#0160;100-year&#0160;cycle&#0160;has&#0160;one&#0160;fewer&#0160;leap&#0160;day&#0160;than&#0160;we'd&#0160;get&#0160;from</span><br />
<a class="lnum" href="#93" name="93">0093</a><span class="comment"></span><span class="comment">#&#0160;pasting&#0160;together&#0160;25&#0160;4-year&#0160;cycles.</span><br />
<a class="lnum" href="#94" name="94">0094</a><span class="comment"></span><span class="keyword">assert</span>&#0160;<span class="name">_DI100Y</span>&#0160;<span class="op">==</span>&#0160;<span class="number">25</span>&#0160;<span class="op">*</span>&#0160;<span class="name">_DI4Y</span>&#0160;<span class="op">-</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#95" name="95">0095</a><br />
<a class="lnum" href="#96" name="96">0096</a><span class="keyword">def</span>&#0160;<span class="name">_ord2ymd</span><span class="op">(</span><span class="name">n</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#97" name="97">0097</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"ordinal&#0160;-&gt;&#0160;(year,&#0160;month,&#0160;day),&#0160;considering&#0160;01-Jan-0001&#0160;as&#0160;day&#0160;1."</span><br />
<a class="lnum" href="#98" name="98">0098</a><br />
<a class="lnum" href="#99" name="99">0099</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;n&#0160;is&#0160;a&#0160;1-based&#0160;index,&#0160;starting&#0160;at&#0160;1-Jan-1.&#0160;&#0160;The&#0160;pattern&#0160;of&#0160;leap&#0160;years</span><br />
<a class="lnum" href="#100" name="100">0100</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;repeats&#0160;exactly&#0160;every&#0160;400&#0160;years.&#0160;&#0160;The&#0160;basic&#0160;strategy&#0160;is&#0160;to&#0160;find&#0160;the</span><br />
<a class="lnum" href="#101" name="101">0101</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;closest&#0160;400-year&#0160;boundary&#0160;at&#0160;or&#0160;before&#0160;n,&#0160;then&#0160;work&#0160;with&#0160;the&#0160;offset</span><br />
<a class="lnum" href="#102" name="102">0102</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;from&#0160;that&#0160;boundary&#0160;to&#0160;n.&#0160;&#0160;Life&#0160;is&#0160;much&#0160;clearer&#0160;if&#0160;we&#0160;subtract&#0160;1&#0160;from</span><br />
<a class="lnum" href="#103" name="103">0103</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;n&#0160;first&#0160;--&#0160;then&#0160;the&#0160;values&#0160;of&#0160;n&#0160;at&#0160;400-year&#0160;boundaries&#0160;are&#0160;exactly</span><br />
<a class="lnum" href="#104" name="104">0104</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;those&#0160;divisible&#0160;by&#0160;_DI400Y:</span><br />
<a class="lnum" href="#105" name="105">0105</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#</span><br />
<a class="lnum" href="#106" name="106">0106</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;D&#0160;&#0160;M&#0160;&#0160;&#0160;Y&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;n&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;n-1</span><br />
<a class="lnum" href="#107" name="107">0107</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;--&#0160;---&#0160;----&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;----------&#0160;&#0160;&#0160;&#0160;&#0160;----------------</span><br />
<a class="lnum" href="#108" name="108">0108</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;31&#0160;Dec&#0160;-400&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-_DI400Y&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-_DI400Y&#0160;-1</span><br />
<a class="lnum" href="#109" name="109">0109</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;1&#0160;Jan&#0160;-399&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-_DI400Y&#0160;+1&#0160;&#0160;&#0160;-_DI400Y&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;400-year&#0160;boundary</span><br />
<a class="lnum" href="#110" name="110">0110</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;...</span><br />
<a class="lnum" href="#111" name="111">0111</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;30&#0160;Dec&#0160;&#0160;000&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-1&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-2</span><br />
<a class="lnum" href="#112" name="112">0112</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;31&#0160;Dec&#0160;&#0160;000&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;0&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-1</span><br />
<a class="lnum" href="#113" name="113">0113</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;1&#0160;Jan&#0160;&#0160;001&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;1&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;0&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;400-year&#0160;boundary</span><br />
<a class="lnum" href="#114" name="114">0114</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;2&#0160;Jan&#0160;&#0160;001&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;2&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;1</span><br />
<a class="lnum" href="#115" name="115">0115</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;3&#0160;Jan&#0160;&#0160;001&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;3&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;2</span><br />
<a class="lnum" href="#116" name="116">0116</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;...</span><br />
<a class="lnum" href="#117" name="117">0117</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;31&#0160;Dec&#0160;&#0160;400&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;_DI400Y&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;_DI400Y&#0160;-1</span><br />
<a class="lnum" href="#118" name="118">0118</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;1&#0160;Jan&#0160;&#0160;401&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;_DI400Y&#0160;+1&#0160;&#0160;&#0160;&#0160;&#0160;_DI400Y&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;400-year&#0160;boundary</span><br />
<a class="lnum" href="#119" name="119">0119</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">n</span>&#0160;<span class="op">-=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#120" name="120">0120</a>&#0160;&#0160;&#0160;&#0160;<span class="name">n400</span><span class="op">,</span>&#0160;<span class="name">n</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">n</span><span class="op">,</span>&#0160;<span class="name">_DI400Y</span><span class="op">)</span><br />
<a class="lnum" href="#121" name="121">0121</a>&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">n400</span>&#0160;<span class="op">*</span>&#0160;<span class="number">400</span>&#0160;<span class="op">+</span>&#0160;<span class="number">1</span>&#0160;&#0160;&#0160;<span class="comment">#&#0160;...,&#0160;-399,&#0160;1,&#0160;401,&#0160;...</span><br />
<a class="lnum" href="#122" name="122">0122</a><br />
<a class="lnum" href="#123" name="123">0123</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Now&#0160;n&#0160;is&#0160;the&#0160;(non-negative)&#0160;offset,&#0160;in&#0160;days,&#0160;from&#0160;January&#0160;1&#0160;of&#0160;year,&#0160;to</span><br />
<a class="lnum" href="#124" name="124">0124</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;the&#0160;desired&#0160;date.&#0160;&#0160;Now&#0160;compute&#0160;how&#0160;many&#0160;100-year&#0160;cycles&#0160;precede&#0160;n.</span><br />
<a class="lnum" href="#125" name="125">0125</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Note&#0160;that&#0160;it's&#0160;possible&#0160;for&#0160;n100&#0160;to&#0160;equal&#0160;4!&#0160;&#0160;In&#0160;that&#0160;case&#0160;4&#0160;full</span><br />
<a class="lnum" href="#126" name="126">0126</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;100-year&#0160;cycles&#0160;precede&#0160;the&#0160;desired&#0160;day,&#0160;which&#0160;implies&#0160;the&#0160;desired</span><br />
<a class="lnum" href="#127" name="127">0127</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;day&#0160;is&#0160;December&#0160;31&#0160;at&#0160;the&#0160;end&#0160;of&#0160;a&#0160;400-year&#0160;cycle.</span><br />
<a class="lnum" href="#128" name="128">0128</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">n100</span><span class="op">,</span>&#0160;<span class="name">n</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">n</span><span class="op">,</span>&#0160;<span class="name">_DI100Y</span><span class="op">)</span><br />
<a class="lnum" href="#129" name="129">0129</a><br />
<a class="lnum" href="#130" name="130">0130</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Now&#0160;compute&#0160;how&#0160;many&#0160;4-year&#0160;cycles&#0160;precede&#0160;it.</span><br />
<a class="lnum" href="#131" name="131">0131</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">n4</span><span class="op">,</span>&#0160;<span class="name">n</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">n</span><span class="op">,</span>&#0160;<span class="name">_DI4Y</span><span class="op">)</span><br />
<a class="lnum" href="#132" name="132">0132</a><br />
<a class="lnum" href="#133" name="133">0133</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;And&#0160;now&#0160;how&#0160;many&#0160;single&#0160;years.&#0160;&#0160;Again&#0160;n1&#0160;can&#0160;be&#0160;4,&#0160;and&#0160;again&#0160;meaning</span><br />
<a class="lnum" href="#134" name="134">0134</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;that&#0160;the&#0160;desired&#0160;day&#0160;is&#0160;December&#0160;31&#0160;at&#0160;the&#0160;end&#0160;of&#0160;the&#0160;4-year&#0160;cycle.</span><br />
<a class="lnum" href="#135" name="135">0135</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">n1</span><span class="op">,</span>&#0160;<span class="name">n</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">n</span><span class="op">,</span>&#0160;<span class="number">365</span><span class="op">)</span><br />
<a class="lnum" href="#136" name="136">0136</a><br />
<a class="lnum" href="#137" name="137">0137</a>&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">n100</span>&#0160;<span class="op">*</span>&#0160;<span class="number">100</span>&#0160;<span class="op">+</span>&#0160;<span class="name">n4</span>&#0160;<span class="op">*</span>&#0160;<span class="number">4</span>&#0160;<span class="op">+</span>&#0160;<span class="name">n1</span><br />
<a class="lnum" href="#138" name="138">0138</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">n1</span>&#0160;<span class="op">==</span>&#0160;<span class="number">4</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">n100</span>&#0160;<span class="op">==</span>&#0160;<span class="number">4</span><span class="op">:</span><br />
<a class="lnum" href="#139" name="139">0139</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">n</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#140" name="140">0140</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">year</span><span class="op">-</span><span class="number">1</span><span class="op">,</span>&#0160;<span class="number">12</span><span class="op">,</span>&#0160;<span class="number">31</span><br />
<a class="lnum" href="#141" name="141">0141</a><br />
<a class="lnum" href="#142" name="142">0142</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Now&#0160;the&#0160;year&#0160;is&#0160;correct,&#0160;and&#0160;n&#0160;is&#0160;the&#0160;offset&#0160;from&#0160;January&#0160;1.&#0160;&#0160;We&#0160;find</span><br />
<a class="lnum" href="#143" name="143">0143</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;the&#0160;month&#0160;via&#0160;an&#0160;estimate&#0160;that's&#0160;either&#0160;exact&#0160;or&#0160;one&#0160;too&#0160;large.</span><br />
<a class="lnum" href="#144" name="144">0144</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">leapyear</span>&#0160;<span class="op">=</span>&#0160;<span class="name">n1</span>&#0160;<span class="op">==</span>&#0160;<span class="number">3</span>&#0160;<span class="keyword">and</span>&#0160;<span class="op">(</span><span class="name">n4</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">24</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">n100</span>&#0160;<span class="op">==</span>&#0160;<span class="number">3</span><span class="op">)</span><br />
<a class="lnum" href="#145" name="145">0145</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">leapyear</span>&#0160;<span class="op">==</span>&#0160;<span class="name">_is_leap</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#146" name="146">0146</a>&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="name">n</span>&#0160;<span class="op">+</span>&#0160;<span class="number">50</span><span class="op">)</span>&#0160;<span class="op">&gt;&gt;</span>&#0160;<span class="number">5</span><br />
<a class="lnum" href="#147" name="147">0147</a>&#0160;&#0160;&#0160;&#0160;<span class="name">preceding</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_DAYS_BEFORE_MONTH</span><span class="op">[</span><span class="name">month</span><span class="op">]</span>&#0160;<span class="op">+</span>&#0160;<span class="op">(</span><span class="name">month</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">2</span>&#0160;<span class="keyword">and</span>&#0160;<span class="name">leapyear</span><span class="op">)</span><br />
<a class="lnum" href="#148" name="148">0148</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">preceding</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="name">n</span><span class="op">:</span>&#0160;&#0160;<span class="comment">#&#0160;estimate&#0160;is&#0160;too&#0160;large</span><br />
<a class="lnum" href="#149" name="149">0149</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">-=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#150" name="150">0150</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">preceding</span>&#0160;<span class="op">-=</span>&#0160;<span class="name">_DAYS_IN_MONTH</span><span class="op">[</span><span class="name">month</span><span class="op">]</span>&#0160;<span class="op">+</span>&#0160;<span class="op">(</span><span class="name">month</span>&#0160;<span class="op">==</span>&#0160;<span class="number">2</span>&#0160;<span class="keyword">and</span>&#0160;<span class="name">leapyear</span><span class="op">)</span><br />
<a class="lnum" href="#151" name="151">0151</a>&#0160;&#0160;&#0160;&#0160;<span class="name">n</span>&#0160;<span class="op">-=</span>&#0160;<span class="name">preceding</span><br />
<a class="lnum" href="#152" name="152">0152</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">n</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="name">_days_in_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#153" name="153">0153</a><br />
<a class="lnum" href="#154" name="154">0154</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Now&#0160;the&#0160;year&#0160;and&#0160;month&#0160;are&#0160;correct,&#0160;and&#0160;n&#0160;is&#0160;the&#0160;offset&#0160;from&#0160;the</span><br />
<a class="lnum" href="#155" name="155">0155</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;start&#0160;of&#0160;that&#0160;month:&#0160;&#0160;we're&#0160;done!</span><br />
<a class="lnum" href="#156" name="156">0156</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">n</span><span class="op">+</span><span class="number">1</span><br />
<a class="lnum" href="#157" name="157">0157</a><br />
<a class="lnum" href="#158" name="158">0158</a><span class="comment">#&#0160;Month&#0160;and&#0160;day&#0160;names.&#0160;&#0160;For&#0160;localized&#0160;versions,&#0160;see&#0160;the&#0160;calendar&#0160;module.</span><br />
<a class="lnum" href="#159" name="159">0159</a><span class="comment"></span><span class="name">_MONTHNAMES</span>&#0160;<span class="op">=</span>&#0160;<span class="op">[</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="string">"Jan"</span><span class="op">,</span>&#0160;<span class="string">"Feb"</span><span class="op">,</span>&#0160;<span class="string">"Mar"</span><span class="op">,</span>&#0160;<span class="string">"Apr"</span><span class="op">,</span>&#0160;<span class="string">"May"</span><span class="op">,</span>&#0160;<span class="string">"Jun"</span><span class="op">,</span><br />
<a class="lnum" href="#160" name="160">0160</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Jul"</span><span class="op">,</span>&#0160;<span class="string">"Aug"</span><span class="op">,</span>&#0160;<span class="string">"Sep"</span><span class="op">,</span>&#0160;<span class="string">"Oct"</span><span class="op">,</span>&#0160;<span class="string">"Nov"</span><span class="op">,</span>&#0160;<span class="string">"Dec"</span><span class="op">]</span><br />
<a class="lnum" href="#161" name="161">0161</a><span class="name">_DAYNAMES</span>&#0160;<span class="op">=</span>&#0160;<span class="op">[</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="string">"Mon"</span><span class="op">,</span>&#0160;<span class="string">"Tue"</span><span class="op">,</span>&#0160;<span class="string">"Wed"</span><span class="op">,</span>&#0160;<span class="string">"Thu"</span><span class="op">,</span>&#0160;<span class="string">"Fri"</span><span class="op">,</span>&#0160;<span class="string">"Sat"</span><span class="op">,</span>&#0160;<span class="string">"Sun"</span><span class="op">]</span><br />
<a class="lnum" href="#162" name="162">0162</a><br />
<a class="lnum" href="#163" name="163">0163</a><br />
<a class="lnum" href="#164" name="164">0164</a><span class="keyword">def</span>&#0160;<span class="name">_build_struct_time</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">dstflag</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#165" name="165">0165</a>&#0160;&#0160;&#0160;&#0160;<span class="name">wday</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="name">_ymd2ord</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">)</span>&#0160;<span class="op">+</span>&#0160;<span class="number">6</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="number">7</span><br />
<a class="lnum" href="#166" name="166">0166</a>&#0160;&#0160;&#0160;&#0160;<span class="name">dnum</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_before_month</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">)</span>&#0160;<span class="op">+</span>&#0160;<span class="name">d</span><br />
<a class="lnum" href="#167" name="167">0167</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">struct_time</span><span class="op">(</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">wday</span><span class="op">,</span>&#0160;<span class="name">dnum</span><span class="op">,</span>&#0160;<span class="name">dstflag</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#168" name="168">0168</a><br />
<a class="lnum" href="#169" name="169">0169</a><span class="keyword">def</span>&#0160;<span class="name">_format_time</span><span class="op">(</span><span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">us</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#170" name="170">0170</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Skip&#0160;trailing&#0160;microseconds&#0160;when&#0160;us==0.</span><br />
<a class="lnum" href="#171" name="171">0171</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">result</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"%02d:%02d:%02d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">)</span><br />
<a class="lnum" href="#172" name="172">0172</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">us</span><span class="op">:</span><br />
<a class="lnum" href="#173" name="173">0173</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">result</span>&#0160;<span class="op">+=</span>&#0160;<span class="string">".%06d"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">us</span><br />
<a class="lnum" href="#174" name="174">0174</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">result</span><br />
<a class="lnum" href="#175" name="175">0175</a><br />
<a class="lnum" href="#176" name="176">0176</a><span class="comment">#&#0160;Correctly&#0160;substitute&#0160;for&#0160;%z&#0160;and&#0160;%Z&#0160;escapes&#0160;in&#0160;strftime&#0160;formats.</span><br />
<a class="lnum" href="#177" name="177">0177</a><span class="comment"></span><span class="keyword">def</span>&#0160;<span class="name">_wrap_strftime</span><span class="op">(</span><span class="name">object</span><span class="op">,</span>&#0160;<span class="name">format</span><span class="op">,</span>&#0160;<span class="name">timetuple</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#178" name="178">0178</a>&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timetuple</span><span class="op">[</span><span class="number">0</span><span class="op">]</span><br />
<a class="lnum" href="#179" name="179">0179</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">year</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">1900</span><span class="op">:</span><br />
<a class="lnum" href="#180" name="180">0180</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"year=%d&#0160;is&#0160;before&#0160;1900;&#0160;the&#0160;datetime&#0160;strftime()&#0160;"</span><br />
<a class="lnum" href="#181" name="181">0181</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"methods&#0160;require&#0160;year&#0160;&gt;=&#0160;1900"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#182" name="182">0182</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Don't&#0160;call&#0160;_utcoffset()&#0160;or&#0160;tzname()&#0160;unless&#0160;actually&#0160;needed.</span><br />
<a class="lnum" href="#183" name="183">0183</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">zreplace</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span>&#0160;<span class="comment">#&#0160;the&#0160;string&#0160;to&#0160;use&#0160;for&#0160;%z</span><br />
<a class="lnum" href="#184" name="184">0184</a>&#0160;&#0160;&#0160;&#0160;<span class="name">Zreplace</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span>&#0160;<span class="comment">#&#0160;the&#0160;string&#0160;to&#0160;use&#0160;for&#0160;%Z</span><br />
<a class="lnum" href="#185" name="185">0185</a><br />
<a class="lnum" href="#186" name="186">0186</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Scan&#0160;format&#0160;for&#0160;%z&#0160;and&#0160;%Z&#0160;escapes,&#0160;replacing&#0160;as&#0160;needed.</span><br />
<a class="lnum" href="#187" name="187">0187</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">newformat</span>&#0160;<span class="op">=</span>&#0160;<span class="op">[</span><span class="op">]</span><br />
<a class="lnum" href="#188" name="188">0188</a>&#0160;&#0160;&#0160;&#0160;<span class="name">push</span>&#0160;<span class="op">=</span>&#0160;<span class="name">newformat</span><span class="op">.</span><span class="name">append</span><br />
<a class="lnum" href="#189" name="189">0189</a>&#0160;&#0160;&#0160;&#0160;<span class="name">i</span><span class="op">,</span>&#0160;<span class="name">n</span>&#0160;<span class="op">=</span>&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">format</span><span class="op">)</span><br />
<a class="lnum" href="#190" name="190">0190</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">while</span>&#0160;<span class="name">i</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="name">n</span><span class="op">:</span><br />
<a class="lnum" href="#191" name="191">0191</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">ch</span>&#0160;<span class="op">=</span>&#0160;<span class="name">format</span><span class="op">[</span><span class="name">i</span><span class="op">]</span><br />
<a class="lnum" href="#192" name="192">0192</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">i</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#193" name="193">0193</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">ch</span>&#0160;<span class="op">==</span>&#0160;<span class="string">'%'</span><span class="op">:</span><br />
<a class="lnum" href="#194" name="194">0194</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">i</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="name">n</span><span class="op">:</span><br />
<a class="lnum" href="#195" name="195">0195</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">ch</span>&#0160;<span class="op">=</span>&#0160;<span class="name">format</span><span class="op">[</span><span class="name">i</span><span class="op">]</span><br />
<a class="lnum" href="#196" name="196">0196</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">i</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#197" name="197">0197</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">ch</span>&#0160;<span class="op">==</span>&#0160;<span class="string">'z'</span><span class="op">:</span><br />
<a class="lnum" href="#198" name="198">0198</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">zreplace</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#199" name="199">0199</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">zreplace</span>&#0160;<span class="op">=</span>&#0160;<span class="string">""</span><br />
<a class="lnum" href="#200" name="200">0200</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">object</span><span class="op">,</span>&#0160;<span class="string">"_utcoffset"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#201" name="201">0201</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">object</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#202" name="202">0202</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#203" name="203">0203</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sign</span>&#0160;<span class="op">=</span>&#0160;<span class="string">'+'</span><br />
<a class="lnum" href="#204" name="204">0204</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#205" name="205">0205</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="op">-</span><span class="name">offset</span><br />
<a class="lnum" href="#206" name="206">0206</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sign</span>&#0160;<span class="op">=</span>&#0160;<span class="string">'-'</span><br />
<a class="lnum" href="#207" name="207">0207</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">h</span><span class="op">,</span>&#0160;<span class="name">m</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">offset</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#208" name="208">0208</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">zreplace</span>&#0160;<span class="op">=</span>&#0160;<span class="string">'%c%02d%02d'</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">sign</span><span class="op">,</span>&#0160;<span class="name">h</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">)</span><br />
<a class="lnum" href="#209" name="209">0209</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="string">'%'</span>&#0160;<span class="keyword">not</span>&#0160;<span class="keyword">in</span>&#0160;<span class="name">zreplace</span><br />
<a class="lnum" href="#210" name="210">0210</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">newformat</span><span class="op">.</span><span class="name">append</span><span class="op">(</span><span class="name">zreplace</span><span class="op">)</span><br />
<a class="lnum" href="#211" name="211">0211</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">ch</span>&#0160;<span class="op">==</span>&#0160;<span class="string">'Z'</span><span class="op">:</span><br />
<a class="lnum" href="#212" name="212">0212</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">Zreplace</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#213" name="213">0213</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">Zreplace</span>&#0160;<span class="op">=</span>&#0160;<span class="string">""</span><br />
<a class="lnum" href="#214" name="214">0214</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">object</span><span class="op">,</span>&#0160;<span class="string">"tzname"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#215" name="215">0215</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">object</span><span class="op">.</span><span class="name">tzname</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#216" name="216">0216</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">s</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#217" name="217">0217</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;strftime&#0160;is&#0160;going&#0160;to&#0160;have&#0160;at&#0160;this:&#0160;escape&#0160;%</span><br />
<a class="lnum" href="#218" name="218">0218</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">Zreplace</span>&#0160;<span class="op">=</span>&#0160;<span class="name">s</span><span class="op">.</span><span class="name">replace</span><span class="op">(</span><span class="string">'%'</span><span class="op">,</span>&#0160;<span class="string">'%%'</span><span class="op">)</span><br />
<a class="lnum" href="#219" name="219">0219</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">newformat</span><span class="op">.</span><span class="name">append</span><span class="op">(</span><span class="name">Zreplace</span><span class="op">)</span><br />
<a class="lnum" href="#220" name="220">0220</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#221" name="221">0221</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">push</span><span class="op">(</span><span class="string">'%'</span><span class="op">)</span><br />
<a class="lnum" href="#222" name="222">0222</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">push</span><span class="op">(</span><span class="name">ch</span><span class="op">)</span><br />
<a class="lnum" href="#223" name="223">0223</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#224" name="224">0224</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">push</span><span class="op">(</span><span class="string">'%'</span><span class="op">)</span><br />
<a class="lnum" href="#225" name="225">0225</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#226" name="226">0226</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">push</span><span class="op">(</span><span class="name">ch</span><span class="op">)</span><br />
<a class="lnum" href="#227" name="227">0227</a>&#0160;&#0160;&#0160;&#0160;<span class="name">newformat</span>&#0160;<span class="op">=</span>&#0160;<span class="string">""</span><span class="op">.</span><span class="name">join</span><span class="op">(</span><span class="name">newformat</span><span class="op">)</span><br />
<a class="lnum" href="#228" name="228">0228</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">strftime</span><span class="op">(</span><span class="name">newformat</span><span class="op">,</span>&#0160;<span class="name">timetuple</span><span class="op">)</span><br />
<a class="lnum" href="#229" name="229">0229</a><br />
<a class="lnum" href="#230" name="230">0230</a><span class="keyword">def</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">,</span>&#0160;<span class="name">methname</span><span class="op">,</span>&#0160;<span class="name">tzinfoarg</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#231" name="231">0231</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#232" name="232">0232</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#233" name="233">0233</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">getattr</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">,</span>&#0160;<span class="name">methname</span><span class="op">)</span><span class="op">(</span><span class="name">tzinfoarg</span><span class="op">)</span><br />
<a class="lnum" href="#234" name="234">0234</a><br />
<a class="lnum" href="#235" name="235">0235</a><span class="comment">#&#0160;Just&#0160;raise&#0160;TypeError&#0160;if&#0160;the&#0160;arg&#0160;isn't&#0160;None&#0160;or&#0160;a&#0160;string.</span><br />
<a class="lnum" href="#236" name="236">0236</a><span class="comment"></span><span class="keyword">def</span>&#0160;<span class="name">_check_tzname</span><span class="op">(</span><span class="name">name</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#237" name="237">0237</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">name</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span>&#0160;<span class="keyword">and</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">name</span><span class="op">,</span>&#0160;<span class="name">str</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#238" name="238">0238</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"tzinfo.tzname()&#0160;must&#0160;return&#0160;None&#0160;or&#0160;string,&#0160;"</span><br />
<a class="lnum" href="#239" name="239">0239</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"not&#0160;'%s'"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">type</span><span class="op">(</span><span class="name">name</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#240" name="240">0240</a><br />
<a class="lnum" href="#241" name="241">0241</a><span class="comment">#&#0160;name&#0160;is&#0160;the&#0160;offset-producing&#0160;method,&#0160;"utcoffset"&#0160;or&#0160;"dst".</span><br />
<a class="lnum" href="#242" name="242">0242</a><span class="comment"></span><span class="comment">#&#0160;offset&#0160;is&#0160;what&#0160;it&#0160;returned.</span><br />
<a class="lnum" href="#243" name="243">0243</a><span class="comment"></span><span class="comment">#&#0160;If&#0160;offset&#0160;isn't&#0160;None&#0160;or&#0160;timedelta,&#0160;raises&#0160;TypeError.</span><br />
<a class="lnum" href="#244" name="244">0244</a><span class="comment"></span><span class="comment">#&#0160;If&#0160;offset&#0160;is&#0160;None,&#0160;returns&#0160;None.</span><br />
<a class="lnum" href="#245" name="245">0245</a><span class="comment"></span><span class="comment">#&#0160;Else&#0160;offset&#0160;is&#0160;checked&#0160;for&#0160;being&#0160;in&#0160;range,&#0160;and&#0160;a&#0160;whole&#0160;#&#0160;of&#0160;minutes.</span><br />
<a class="lnum" href="#246" name="246">0246</a><span class="comment"></span><span class="comment">#&#0160;If&#0160;it&#0160;is,&#0160;its&#0160;integer&#0160;value&#0160;is&#0160;returned.&#0160;&#0160;Else&#0160;ValueError&#0160;is&#0160;raised.</span><br />
<a class="lnum" href="#247" name="247">0247</a><span class="comment"></span><span class="keyword">def</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="name">name</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#248" name="248">0248</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">name</span>&#0160;<span class="keyword">in</span>&#0160;<span class="op">(</span><span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="string">"dst"</span><span class="op">)</span><br />
<a class="lnum" href="#249" name="249">0249</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#250" name="250">0250</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#251" name="251">0251</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">offset</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#252" name="252">0252</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"tzinfo.%s()&#0160;must&#0160;return&#0160;None&#0160;"</span><br />
<a class="lnum" href="#253" name="253">0253</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"or&#0160;timedelta,&#0160;not&#0160;'%s'"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">name</span><span class="op">,</span>&#0160;<span class="name">type</span><span class="op">(</span><span class="name">offset</span><span class="op">)</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#254" name="254">0254</a>&#0160;&#0160;&#0160;&#0160;<span class="name">days</span>&#0160;<span class="op">=</span>&#0160;<span class="name">offset</span><span class="op">.</span><span class="name">days</span><br />
<a class="lnum" href="#255" name="255">0255</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">days</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="op">-</span><span class="number">1</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">days</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#256" name="256">0256</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="number">1440</span>&#0160;&#0160;<span class="comment">#&#0160;trigger&#0160;out-of-range</span><br />
<a class="lnum" href="#257" name="257">0257</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#258" name="258">0258</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">days</span>&#0160;<span class="op">*</span>&#0160;<span class="number">86400</span>&#0160;<span class="op">+</span>&#0160;<span class="name">offset</span><span class="op">.</span><span class="name">seconds</span><br />
<a class="lnum" href="#259" name="259">0259</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">minutes</span><span class="op">,</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">seconds</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#260" name="260">0260</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">seconds</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">offset</span><span class="op">.</span><span class="name">microseconds</span><span class="op">:</span><br />
<a class="lnum" href="#261" name="261">0261</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"tzinfo.%s()&#0160;must&#0160;return&#0160;a&#0160;whole&#0160;number&#0160;"</span><br />
<a class="lnum" href="#262" name="262">0262</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"of&#0160;minutes"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">name</span><span class="op">)</span><br />
<a class="lnum" href="#263" name="263">0263</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">minutes</span><br />
<a class="lnum" href="#264" name="264">0264</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="op">-</span><span class="number">1440</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="name">offset</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">1440</span><span class="op">:</span><br />
<a class="lnum" href="#265" name="265">0265</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#266" name="266">0266</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"%s()=%d,&#0160;must&#0160;be&#0160;in&#0160;-1439..1439"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">name</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#267" name="267">0267</a><br />
<a class="lnum" href="#268" name="268">0268</a><span class="keyword">def</span>&#0160;<span class="name">_check_date_fields</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#269" name="269">0269</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">MINYEAR</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">year</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">MAXYEAR</span><span class="op">:</span><br />
<a class="lnum" href="#270" name="270">0270</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'year&#0160;must&#0160;be&#0160;in&#0160;%d..%d'</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">MINYEAR</span><span class="op">,</span>&#0160;<span class="name">MAXYEAR</span><span class="op">)</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#271" name="271">0271</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">12</span><span class="op">:</span><br />
<a class="lnum" href="#272" name="272">0272</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'month&#0160;must&#0160;be&#0160;in&#0160;1..12'</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#273" name="273">0273</a>&#0160;&#0160;&#0160;&#0160;<span class="name">dim</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_in_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#274" name="274">0274</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">day</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">dim</span><span class="op">:</span><br />
<a class="lnum" href="#275" name="275">0275</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'day&#0160;must&#0160;be&#0160;in&#0160;1..%d'</span>&#0160;<span class="op">%</span>&#0160;<span class="name">dim</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#276" name="276">0276</a><br />
<a class="lnum" href="#277" name="277">0277</a><span class="keyword">def</span>&#0160;<span class="name">_check_time_fields</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#278" name="278">0278</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">hour</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">23</span><span class="op">:</span><br />
<a class="lnum" href="#279" name="279">0279</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'hour&#0160;must&#0160;be&#0160;in&#0160;0..23'</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">)</span><br />
<a class="lnum" href="#280" name="280">0280</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">minute</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">59</span><span class="op">:</span><br />
<a class="lnum" href="#281" name="281">0281</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'minute&#0160;must&#0160;be&#0160;in&#0160;0..59'</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">)</span><br />
<a class="lnum" href="#282" name="282">0282</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">second</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">59</span><span class="op">:</span><br />
<a class="lnum" href="#283" name="283">0283</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'second&#0160;must&#0160;be&#0160;in&#0160;0..59'</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">)</span><br />
<a class="lnum" href="#284" name="284">0284</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">microsecond</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">999999</span><span class="op">:</span><br />
<a class="lnum" href="#285" name="285">0285</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">'microsecond&#0160;must&#0160;be&#0160;in&#0160;0..999999'</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#286" name="286">0286</a><br />
<a class="lnum" href="#287" name="287">0287</a><span class="keyword">def</span>&#0160;<span class="name">_check_tzinfo_arg</span><span class="op">(</span><span class="name">tz</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#288" name="288">0288</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span>&#0160;<span class="keyword">and</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">tz</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#289" name="289">0289</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"tzinfo&#0160;argument&#0160;must&#0160;be&#0160;None&#0160;or&#0160;of&#0160;a&#0160;tzinfo&#0160;subclass"</span><span class="op">)</span><br />
<a class="lnum" href="#290" name="290">0290</a><br />
<a class="lnum" href="#291" name="291">0291</a><br />
<a class="lnum" href="#292" name="292">0292</a><span class="comment">#&#0160;Notes&#0160;on&#0160;comparison:&#0160;&#0160;In&#0160;general,&#0160;datetime&#0160;module&#0160;comparison&#0160;operators&#0160;raise</span><br />
<a class="lnum" href="#293" name="293">0293</a><span class="comment"></span><span class="comment">#&#0160;TypeError&#0160;when&#0160;they&#0160;don't&#0160;know&#0160;how&#0160;to&#0160;do&#0160;a&#0160;comparison&#0160;themself.&#0160;&#0160;If&#0160;they</span><br />
<a class="lnum" href="#294" name="294">0294</a><span class="comment"></span><span class="comment">#&#0160;returned&#0160;NotImplemented&#0160;instead,&#0160;comparison&#0160;could&#0160;(silently)&#0160;fall&#0160;back&#0160;to</span><br />
<a class="lnum" href="#295" name="295">0295</a><span class="comment"></span><span class="comment">#&#0160;the&#0160;default&#0160;compare-objects-by-comparing-their-memory-addresses&#0160;strategy,</span><br />
<a class="lnum" href="#296" name="296">0296</a><span class="comment"></span><span class="comment">#&#0160;and&#0160;that's&#0160;not&#0160;helpful.&#0160;&#0160;There&#0160;are&#0160;two&#0160;exceptions:</span><br />
<a class="lnum" href="#297" name="297">0297</a><span class="comment"></span><span class="comment">#</span><br />
<a class="lnum" href="#298" name="298">0298</a><span class="comment"></span><span class="comment">#&#0160;1.&#0160;For&#0160;date&#0160;and&#0160;datetime,&#0160;if&#0160;the&#0160;other&#0160;object&#0160;has&#0160;a&#0160;"timetuple"&#0160;attr,</span><br />
<a class="lnum" href="#299" name="299">0299</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;NotImplemented&#0160;is&#0160;returned.&#0160;&#0160;This&#0160;is&#0160;a&#0160;hook&#0160;to&#0160;allow&#0160;other&#0160;kinds&#0160;of</span><br />
<a class="lnum" href="#300" name="300">0300</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;datetime-like&#0160;objects&#0160;a&#0160;chance&#0160;to&#0160;intercept&#0160;the&#0160;comparison.</span><br />
<a class="lnum" href="#301" name="301">0301</a><span class="comment"></span><span class="comment">#</span><br />
<a class="lnum" href="#302" name="302">0302</a><span class="comment"></span><span class="comment">#&#0160;2.&#0160;Else&#0160;__eq__&#0160;and&#0160;__ne__&#0160;return&#0160;False&#0160;and&#0160;True,&#0160;respectively.&#0160;&#0160;This&#0160;is</span><br />
<a class="lnum" href="#303" name="303">0303</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;so&#0160;opertaions&#0160;like</span><br />
<a class="lnum" href="#304" name="304">0304</a><span class="comment"></span><span class="comment">#</span><br />
<a class="lnum" href="#305" name="305">0305</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x&#0160;==&#0160;y</span><br />
<a class="lnum" href="#306" name="306">0306</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x&#0160;!=&#0160;y</span><br />
<a class="lnum" href="#307" name="307">0307</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x&#0160;in&#0160;sequence</span><br />
<a class="lnum" href="#308" name="308">0308</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x&#0160;not&#0160;in&#0160;sequence</span><br />
<a class="lnum" href="#309" name="309">0309</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;dict[x]&#0160;=&#0160;y</span><br />
<a class="lnum" href="#310" name="310">0310</a><span class="comment"></span><span class="comment">#</span><br />
<a class="lnum" href="#311" name="311">0311</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;don't&#0160;raise&#0160;annoying&#0160;TypeErrors&#0160;just&#0160;because&#0160;a&#0160;datetime&#0160;object</span><br />
<a class="lnum" href="#312" name="312">0312</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;is&#0160;part&#0160;of&#0160;a&#0160;heterogeneous&#0160;collection.&#0160;&#0160;If&#0160;there's&#0160;no&#0160;known&#0160;way&#0160;to</span><br />
<a class="lnum" href="#313" name="313">0313</a><span class="comment"></span><span class="comment">#&#0160;&#0160;&#0160;&#0160;compare&#0160;X&#0160;to&#0160;a&#0160;datetime,&#0160;saying&#0160;they're&#0160;not&#0160;equal&#0160;is&#0160;reasonable.</span><br />
<a class="lnum" href="#314" name="314">0314</a><span class="comment"></span><br />
<a class="lnum" href="#315" name="315">0315</a><span class="keyword">def</span>&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">x</span><span class="op">,</span>&#0160;<span class="name">y</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#316" name="316">0316</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"can't&#0160;compare&#0160;'%s'&#0160;to&#0160;'%s'"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><br />
<a class="lnum" href="#317" name="317">0317</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">type</span><span class="op">(</span><span class="name">x</span><span class="op">)</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span>&#0160;<span class="name">type</span><span class="op">(</span><span class="name">y</span><span class="op">)</span><span class="op">.</span><span class="name">__name__</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#318" name="318">0318</a><br />
<a class="lnum" href="#319" name="319">0319</a><span class="comment">#&#0160;This&#0160;is&#0160;a&#0160;start&#0160;at&#0160;a&#0160;struct&#0160;tm&#0160;workalike.&#0160;&#0160;Goals:</span><br />
<a class="lnum" href="#320" name="320">0320</a><span class="comment"></span><span class="comment">#</span><br />
<a class="lnum" href="#321" name="321">0321</a><span class="comment"></span><span class="comment">#&#0160;+&#0160;Works&#0160;the&#0160;same&#0160;way&#0160;across&#0160;platforms.</span><br />
<a class="lnum" href="#322" name="322">0322</a><span class="comment"></span><span class="comment">#&#0160;+&#0160;Handles&#0160;all&#0160;the&#0160;fields&#0160;datetime&#0160;needs&#0160;handled,&#0160;without&#0160;1970-2038&#0160;glitches.</span><br />
<a class="lnum" href="#323" name="323">0323</a><span class="comment"></span><span class="comment">#</span><br />
<a class="lnum" href="#324" name="324">0324</a><span class="comment"></span><span class="comment">#&#0160;Note:&#0160;&#0160;I&#0160;suspect&#0160;it's&#0160;best&#0160;if&#0160;this&#0160;flavor&#0160;of&#0160;tm&#0160;does&#0160;*not*&#0160;try&#0160;to</span><br />
<a class="lnum" href="#325" name="325">0325</a><span class="comment"></span><span class="comment">#&#0160;second-guess&#0160;timezones&#0160;or&#0160;DST.&#0160;&#0160;Instead&#0160;fold&#0160;whatever&#0160;adjustments&#0160;you&#0160;want</span><br />
<a class="lnum" href="#326" name="326">0326</a><span class="comment"></span><span class="comment">#&#0160;into&#0160;the&#0160;minutes&#0160;argument&#0160;(and&#0160;the&#0160;constructor&#0160;will&#0160;normalize).</span><br />
<a class="lnum" href="#327" name="327">0327</a><span class="comment"></span><br />
<a class="lnum" href="#328" name="328">0328</a><span class="name">_ORD1970</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="number">1970</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">)</span>&#0160;<span class="comment">#&#0160;base&#0160;ordinal&#0160;for&#0160;UNIX&#0160;epoch</span><br />
<a class="lnum" href="#329" name="329">0329</a><br />
<a class="lnum" href="#330" name="330">0330</a><span class="keyword">class</span>&#0160;<span class="name">tmxxx</span><span class="op">:</span><br />
<a class="lnum" href="#331" name="331">0331</a><br />
<a class="lnum" href="#332" name="332">0332</a>&#0160;&#0160;&#0160;&#0160;<span class="name">ordinal</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#333" name="333">0333</a><br />
<a class="lnum" href="#334" name="334">0334</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__init__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">=</span><span class="number">0</span><span class="op">,</span><br />
<a class="lnum" href="#335" name="335">0335</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span><span class="op">=</span><span class="number">0</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#336" name="336">0336</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Normalize&#0160;all&#0160;the&#0160;inputs,&#0160;and&#0160;store&#0160;the&#0160;normalized&#0160;values.</span><br />
<a class="lnum" href="#337" name="337">0337</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">microsecond</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">999999</span><span class="op">:</span><br />
<a class="lnum" href="#338" name="338">0338</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">carry</span><span class="op">,</span>&#0160;<span class="name">microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">microsecond</span><span class="op">,</span>&#0160;<span class="number">1000000</span><span class="op">)</span><br />
<a class="lnum" href="#339" name="339">0339</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">second</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">carry</span><br />
<a class="lnum" href="#340" name="340">0340</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">second</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">59</span><span class="op">:</span><br />
<a class="lnum" href="#341" name="341">0341</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">carry</span><span class="op">,</span>&#0160;<span class="name">second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">second</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#342" name="342">0342</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">minute</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">carry</span><br />
<a class="lnum" href="#343" name="343">0343</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">minute</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">59</span><span class="op">:</span><br />
<a class="lnum" href="#344" name="344">0344</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">carry</span><span class="op">,</span>&#0160;<span class="name">minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#345" name="345">0345</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hour</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">carry</span><br />
<a class="lnum" href="#346" name="346">0346</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">hour</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">23</span><span class="op">:</span><br />
<a class="lnum" href="#347" name="347">0347</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">carry</span><span class="op">,</span>&#0160;<span class="name">hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="number">24</span><span class="op">)</span><br />
<a class="lnum" href="#348" name="348">0348</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">day</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">carry</span><br />
<a class="lnum" href="#349" name="349">0349</a><br />
<a class="lnum" href="#350" name="350">0350</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;That&#0160;was&#0160;easy.&#0160;&#0160;Now&#0160;it&#0160;gets&#0160;muddy:&#0160;&#0160;the&#0160;proper&#0160;range&#0160;for&#0160;day</span><br />
<a class="lnum" href="#351" name="351">0351</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;can't&#0160;be&#0160;determined&#0160;without&#0160;knowing&#0160;the&#0160;correct&#0160;month&#0160;and&#0160;year,</span><br />
<a class="lnum" href="#352" name="352">0352</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;but&#0160;if&#0160;day&#0160;is,&#0160;e.g.,&#0160;plus&#0160;or&#0160;minus&#0160;a&#0160;million,&#0160;the&#0160;current&#0160;month</span><br />
<a class="lnum" href="#353" name="353">0353</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;and&#0160;year&#0160;values&#0160;make&#0160;no&#0160;sense&#0160;(and&#0160;may&#0160;also&#0160;be&#0160;out&#0160;of&#0160;bounds</span><br />
<a class="lnum" href="#354" name="354">0354</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;themselves).</span><br />
<a class="lnum" href="#355" name="355">0355</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Saying&#0160;12&#0160;months&#0160;==&#0160;1&#0160;year&#0160;should&#0160;be&#0160;non-controversial.</span><br />
<a class="lnum" href="#356" name="356">0356</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">12</span><span class="op">:</span><br />
<a class="lnum" href="#357" name="357">0357</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">carry</span><span class="op">,</span>&#0160;<span class="name">month</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">month</span><span class="op">-</span><span class="number">1</span><span class="op">,</span>&#0160;<span class="number">12</span><span class="op">)</span><br />
<a class="lnum" href="#358" name="358">0358</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">carry</span><br />
<a class="lnum" href="#359" name="359">0359</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#360" name="360">0360</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">12</span><br />
<a class="lnum" href="#361" name="361">0361</a><br />
<a class="lnum" href="#362" name="362">0362</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Now&#0160;only&#0160;day&#0160;can&#0160;be&#0160;out&#0160;of&#0160;bounds&#0160;(year&#0160;may&#0160;also&#0160;be&#0160;out&#0160;of&#0160;bounds</span><br />
<a class="lnum" href="#363" name="363">0363</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;for&#0160;a&#0160;datetime&#0160;object,&#0160;but&#0160;we&#0160;don't&#0160;care&#0160;about&#0160;that&#0160;here).</span><br />
<a class="lnum" href="#364" name="364">0364</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;If&#0160;day&#0160;is&#0160;out&#0160;of&#0160;bounds,&#0160;what&#0160;to&#0160;do&#0160;is&#0160;arguable,&#0160;but&#0160;at&#0160;least&#0160;the</span><br />
<a class="lnum" href="#365" name="365">0365</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;method&#0160;here&#0160;is&#0160;principled&#0160;and&#0160;explainable.</span><br />
<a class="lnum" href="#366" name="366">0366</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dim</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_in_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#367" name="367">0367</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">day</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">dim</span><span class="op">:</span><br />
<a class="lnum" href="#368" name="368">0368</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Move&#0160;day-1&#0160;days&#0160;from&#0160;the&#0160;first&#0160;of&#0160;the&#0160;month.&#0160;&#0160;First&#0160;try&#0160;to</span><br />
<a class="lnum" href="#369" name="369">0369</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;get&#0160;off&#0160;cheap&#0160;if&#0160;we're&#0160;only&#0160;one&#0160;day&#0160;out&#0160;of&#0160;range&#0160;(adjustments</span><br />
<a class="lnum" href="#370" name="370">0370</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;for&#0160;timezone&#0160;alone&#0160;can't&#0160;be&#0160;worse&#0160;than&#0160;that).</span><br />
<a class="lnum" href="#371" name="371">0371</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">day</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><span class="op">:</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;move&#0160;back&#0160;a&#0160;day</span><br />
<a class="lnum" href="#372" name="372">0372</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">-=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#373" name="373">0373</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#374" name="374">0374</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_days_in_month</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><br />
<a class="lnum" href="#375" name="375">0375</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#376" name="376">0376</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">year</span><span class="op">-</span><span class="number">1</span><span class="op">,</span>&#0160;<span class="number">12</span><span class="op">,</span>&#0160;<span class="number">31</span><br />
<a class="lnum" href="#377" name="377">0377</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">day</span>&#0160;<span class="op">==</span>&#0160;<span class="name">dim</span>&#0160;<span class="op">+</span>&#0160;<span class="number">1</span><span class="op">:</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;move&#0160;forward&#0160;a&#0160;day</span><br />
<a class="lnum" href="#378" name="378">0378</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#379" name="379">0379</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#380" name="380">0380</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">month</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">12</span><span class="op">:</span><br />
<a class="lnum" href="#381" name="381">0381</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#382" name="382">0382</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#383" name="383">0383</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#384" name="384">0384</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">ordinal</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">)</span>&#0160;<span class="op">+</span>&#0160;<span class="op">(</span><span class="name">day</span>&#0160;<span class="op">-</span>&#0160;<span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#385" name="385">0385</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ord2ymd</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">ordinal</span><span class="op">)</span><br />
<a class="lnum" href="#386" name="386">0386</a><br />
<a class="lnum" href="#387" name="387">0387</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><br />
<a class="lnum" href="#388" name="388">0388</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><br />
<a class="lnum" href="#389" name="389">0389</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">microsecond</span><br />
<a class="lnum" href="#390" name="390">0390</a><br />
<a class="lnum" href="#391" name="391">0391</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">toordinal</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#392" name="392">0392</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;proleptic&#0160;Gregorian&#0160;ordinal&#0160;for&#0160;the&#0160;year,&#0160;month&#0160;and&#0160;day.</span><br />
<a class="lnum" href="#393" name="393">0393</a><span class="string"></span><br />
<a class="lnum" href="#394" name="394">0394</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;January&#0160;1&#0160;of&#0160;year&#0160;1&#0160;is&#0160;day&#0160;1.&#0160;&#0160;Only&#0160;the&#0160;year,&#0160;month&#0160;and&#0160;day&#0160;values</span><br />
<a class="lnum" href="#395" name="395">0395</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;contribute&#0160;to&#0160;the&#0160;result.</span><br />
<a class="lnum" href="#396" name="396">0396</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#397" name="397">0397</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">ordinal</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#398" name="398">0398</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">ordinal</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#399" name="399">0399</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">ordinal</span><br />
<a class="lnum" href="#400" name="400">0400</a><br />
<a class="lnum" href="#401" name="401">0401</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#402" name="402">0402</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;Unixish&#0160;timestamp,&#0160;as&#0160;a&#0160;float&#0160;(assuming&#0160;UTC)."</span><br />
<a class="lnum" href="#403" name="403">0403</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span>&#0160;<span class="op">-</span>&#0160;<span class="name">_ORD1970</span>&#0160;&#0160;&#0160;<span class="comment">#&#0160;convert&#0160;to&#0160;UNIX&#0160;epoch</span><br />
<a class="lnum" href="#404" name="404">0404</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="op">(</span><span class="name">days</span>&#0160;<span class="op">*</span>&#0160;<span class="number">24.</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">)</span><span class="op">*</span><span class="number">60.</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">)</span><span class="op">*</span><span class="number">60.</span><br />
<a class="lnum" href="#405" name="405">0405</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span>&#0160;<span class="op">/</span>&#0160;<span class="number">1e6</span><br />
<a class="lnum" href="#406" name="406">0406</a><br />
<a class="lnum" href="#407" name="407">0407</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">ctime</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#408" name="408">0408</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;ctime()&#0160;style&#0160;string."</span><br />
<a class="lnum" href="#409" name="409">0409</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">weekday</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="number">7</span>&#0160;<span class="keyword">or</span>&#0160;<span class="number">7</span><br />
<a class="lnum" href="#410" name="410">0410</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="string">"%s&#0160;%s&#0160;%2d&#0160;%02d:%02d:%02d&#0160;%04d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><br />
<a class="lnum" href="#411" name="411">0411</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_DAYNAMES</span><span class="op">[</span><span class="name">weekday</span><span class="op">]</span><span class="op">,</span><br />
<a class="lnum" href="#412" name="412">0412</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_MONTHNAMES</span><span class="op">[</span><span class="name">self</span><span class="op">.</span><span class="name">month</span><span class="op">]</span><span class="op">,</span><br />
<a class="lnum" href="#413" name="413">0413</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span><span class="op">,</span><br />
<a class="lnum" href="#414" name="414">0414</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><span class="op">,</span><br />
<a class="lnum" href="#415" name="415">0415</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#416" name="416">0416</a><br />
<a class="lnum" href="#417" name="417">0417</a><span class="keyword">class</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">object</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#418" name="418">0418</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"""Represent&#0160;the&#0160;difference&#0160;between&#0160;two&#0160;datetime&#0160;objects.</span><br />
<a class="lnum" href="#419" name="419">0419</a><span class="string"></span><br />
<a class="lnum" href="#420" name="420">0420</a><span class="string">&#0160;&#0160;&#0160;&#0160;Supported&#0160;operators:</span><br />
<a class="lnum" href="#421" name="421">0421</a><span class="string"></span><br />
<a class="lnum" href="#422" name="422">0422</a><span class="string">&#0160;&#0160;&#0160;&#0160;-&#0160;add,&#0160;subtract&#0160;timedelta</span><br />
<a class="lnum" href="#423" name="423">0423</a><span class="string">&#0160;&#0160;&#0160;&#0160;-&#0160;unary&#0160;plus,&#0160;minus,&#0160;abs</span><br />
<a class="lnum" href="#424" name="424">0424</a><span class="string">&#0160;&#0160;&#0160;&#0160;-&#0160;compare&#0160;to&#0160;timedelta</span><br />
<a class="lnum" href="#425" name="425">0425</a><span class="string">&#0160;&#0160;&#0160;&#0160;-&#0160;multiply,&#0160;divide&#0160;by&#0160;int/long</span><br />
<a class="lnum" href="#426" name="426">0426</a><span class="string"></span><br />
<a class="lnum" href="#427" name="427">0427</a><span class="string">&#0160;&#0160;&#0160;&#0160;In&#0160;addition,&#0160;datetime&#0160;supports&#0160;subtraction&#0160;of&#0160;two&#0160;datetime&#0160;objects</span><br />
<a class="lnum" href="#428" name="428">0428</a><span class="string">&#0160;&#0160;&#0160;&#0160;returning&#0160;a&#0160;timedelta,&#0160;and&#0160;addition&#0160;or&#0160;subtraction&#0160;of&#0160;a&#0160;datetime</span><br />
<a class="lnum" href="#429" name="429">0429</a><span class="string">&#0160;&#0160;&#0160;&#0160;and&#0160;a&#0160;timedelta&#0160;giving&#0160;a&#0160;datetime.</span><br />
<a class="lnum" href="#430" name="430">0430</a><span class="string"></span><br />
<a class="lnum" href="#431" name="431">0431</a><span class="string">&#0160;&#0160;&#0160;&#0160;Representation:&#0160;(days,&#0160;seconds,&#0160;microseconds).&#0160;&#0160;Why?&#0160;&#0160;Because&#0160;I</span><br />
<a class="lnum" href="#432" name="432">0432</a><span class="string">&#0160;&#0160;&#0160;&#0160;felt&#0160;like&#0160;it.</span><br />
<a class="lnum" href="#433" name="433">0433</a><span class="string">&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#434" name="434">0434</a><br />
<a class="lnum" href="#435" name="435">0435</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">days</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">seconds</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">microseconds</span><span class="op">=</span><span class="number">0</span><span class="op">,</span><br />
<a class="lnum" href="#436" name="436">0436</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;The&#0160;following&#0160;should&#0160;only&#0160;be&#0160;used&#0160;as&#0160;keyword&#0160;args:</span><br />
<a class="lnum" href="#437" name="437">0437</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">milliseconds</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">minutes</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">hours</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">weeks</span><span class="op">=</span><span class="number">0</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#438" name="438">0438</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Doing&#0160;this&#0160;efficiently&#0160;and&#0160;accurately&#0160;in&#0160;C&#0160;is&#0160;going&#0160;to&#0160;be&#0160;difficult</span><br />
<a class="lnum" href="#439" name="439">0439</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;and&#0160;error-prone,&#0160;due&#0160;to&#0160;ubiquitous&#0160;overflow&#0160;possibilities,&#0160;and&#0160;that</span><br />
<a class="lnum" href="#440" name="440">0440</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;C&#0160;double&#0160;doesn't&#0160;have&#0160;enough&#0160;bits&#0160;of&#0160;precision&#0160;to&#0160;represent</span><br />
<a class="lnum" href="#441" name="441">0441</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;microseconds&#0160;over&#0160;10K&#0160;years&#0160;faithfully.&#0160;&#0160;The&#0160;code&#0160;here&#0160;tries&#0160;to&#0160;make</span><br />
<a class="lnum" href="#442" name="442">0442</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;explicit&#0160;where&#0160;go-fast&#0160;assumptions&#0160;can&#0160;be&#0160;relied&#0160;on,&#0160;in&#0160;order&#0160;to</span><br />
<a class="lnum" href="#443" name="443">0443</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;guide&#0160;the&#0160;C&#0160;implementation;&#0160;it's&#0160;way&#0160;more&#0160;convoluted&#0160;than&#0160;speed-</span><br />
<a class="lnum" href="#444" name="444">0444</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;ignoring&#0160;auto-overflow-to-long&#0160;idiomatic&#0160;Python&#0160;could&#0160;be.</span><br />
<a class="lnum" href="#445" name="445">0445</a><span class="comment"></span><br />
<a class="lnum" href="#446" name="446">0446</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;Check&#0160;that&#0160;all&#0160;inputs&#0160;are&#0160;ints,&#0160;longs&#0160;or&#0160;floats.</span><br />
<a class="lnum" href="#447" name="447">0447</a><span class="comment"></span><br />
<a class="lnum" href="#448" name="448">0448</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Final&#0160;values,&#0160;all&#0160;integer.</span><br />
<a class="lnum" href="#449" name="449">0449</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;s&#0160;and&#0160;us&#0160;fit&#0160;in&#0160;32-bit&#0160;signed&#0160;ints;&#0160;d&#0160;isn't&#0160;bounded.</span><br />
<a class="lnum" href="#450" name="450">0450</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">us</span>&#0160;<span class="op">=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#451" name="451">0451</a><br />
<a class="lnum" href="#452" name="452">0452</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Normalize&#0160;everything&#0160;to&#0160;days,&#0160;seconds,&#0160;microseconds.</span><br />
<a class="lnum" href="#453" name="453">0453</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">weeks</span><span class="op">*</span><span class="number">7</span><br />
<a class="lnum" href="#454" name="454">0454</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">minutes</span><span class="op">*</span><span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">hours</span><span class="op">*</span><span class="number">3600</span><br />
<a class="lnum" href="#455" name="455">0455</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">milliseconds</span><span class="op">*</span><span class="number">1000</span><br />
<a class="lnum" href="#456" name="456">0456</a><br />
<a class="lnum" href="#457" name="457">0457</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Get&#0160;rid&#0160;of&#0160;all&#0160;fractions,&#0160;and&#0160;normalize&#0160;s&#0160;and&#0160;us.</span><br />
<a class="lnum" href="#458" name="458">0458</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Take&#0160;a&#0160;deep&#0160;breath&#0160;&lt;wink&gt;.</span><br />
<a class="lnum" href="#459" name="459">0459</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">days</span><span class="op">,</span>&#0160;<span class="name">float</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#460" name="460">0460</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dayfrac</span><span class="op">,</span>&#0160;<span class="name">days</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_math</span><span class="op">.</span><span class="name">modf</span><span class="op">(</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#461" name="461">0461</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">daysecondsfrac</span><span class="op">,</span>&#0160;<span class="name">daysecondswhole</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_math</span><span class="op">.</span><span class="name">modf</span><span class="op">(</span><span class="name">dayfrac</span>&#0160;<span class="op">*</span>&#0160;<span class="op">(</span><span class="number">24.</span><span class="op">*</span><span class="number">3600.</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#462" name="462">0462</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">daysecondswhole</span>&#0160;<span class="op">==</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">daysecondswhole</span><span class="op">)</span>&#0160;&#0160;<span class="comment">#&#0160;can't&#0160;overflow</span><br />
<a class="lnum" href="#463" name="463">0463</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">daysecondswhole</span><span class="op">)</span><br />
<a class="lnum" href="#464" name="464">0464</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">days</span>&#0160;<span class="op">==</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#465" name="465">0465</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#466" name="466">0466</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#467" name="467">0467</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">daysecondsfrac</span>&#0160;<span class="op">=</span>&#0160;<span class="number">0.0</span><br />
<a class="lnum" href="#468" name="468">0468</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">days</span><br />
<a class="lnum" href="#469" name="469">0469</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">daysecondsfrac</span><span class="op">,</span>&#0160;<span class="name">float</span><span class="op">)</span><br />
<a class="lnum" href="#470" name="470">0470</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">daysecondsfrac</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">1.0</span><br />
<a class="lnum" href="#471" name="471">0471</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">d</span><span class="op">,</span>&#0160;<span class="op">(</span><span class="name">int</span><span class="op">,</span>&#0160;<span class="name">long</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#472" name="472">0472</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">s</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">24</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#473" name="473">0473</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;days&#0160;isn't&#0160;referenced&#0160;again&#0160;before&#0160;redefinition</span><br />
<a class="lnum" href="#474" name="474">0474</a><span class="comment"></span><br />
<a class="lnum" href="#475" name="475">0475</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">seconds</span><span class="op">,</span>&#0160;<span class="name">float</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#476" name="476">0476</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">secondsfrac</span><span class="op">,</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_math</span><span class="op">.</span><span class="name">modf</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span><br />
<a class="lnum" href="#477" name="477">0477</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">==</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span><br />
<a class="lnum" href="#478" name="478">0478</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span><br />
<a class="lnum" href="#479" name="479">0479</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">secondsfrac</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">daysecondsfrac</span><br />
<a class="lnum" href="#480" name="480">0480</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">secondsfrac</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">2.0</span><br />
<a class="lnum" href="#481" name="481">0481</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#482" name="482">0482</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">secondsfrac</span>&#0160;<span class="op">=</span>&#0160;<span class="name">daysecondsfrac</span><br />
<a class="lnum" href="#483" name="483">0483</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;daysecondsfrac&#0160;isn't&#0160;referenced&#0160;again</span><br />
<a class="lnum" href="#484" name="484">0484</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">secondsfrac</span><span class="op">,</span>&#0160;<span class="name">float</span><span class="op">)</span><br />
<a class="lnum" href="#485" name="485">0485</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">secondsfrac</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">2.0</span><br />
<a class="lnum" href="#486" name="486">0486</a><br />
<a class="lnum" href="#487" name="487">0487</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">seconds</span><span class="op">,</span>&#0160;<span class="op">(</span><span class="name">int</span><span class="op">,</span>&#0160;<span class="name">long</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#488" name="488">0488</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span><span class="op">,</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">seconds</span><span class="op">,</span>&#0160;<span class="number">24</span><span class="op">*</span><span class="number">3600</span><span class="op">)</span><br />
<a class="lnum" href="#489" name="489">0489</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">days</span><br />
<a class="lnum" href="#490" name="490">0490</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;can't&#0160;overflow</span><br />
<a class="lnum" href="#491" name="491">0491</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">s</span><span class="op">,</span>&#0160;<span class="name">int</span><span class="op">)</span><br />
<a class="lnum" href="#492" name="492">0492</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">s</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">2</span>&#0160;<span class="op">*</span>&#0160;<span class="number">24</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#493" name="493">0493</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;seconds&#0160;isn't&#0160;referenced&#0160;again&#0160;before&#0160;redefinition</span><br />
<a class="lnum" href="#494" name="494">0494</a><span class="comment"></span><br />
<a class="lnum" href="#495" name="495">0495</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">usdouble</span>&#0160;<span class="op">=</span>&#0160;<span class="name">secondsfrac</span>&#0160;<span class="op">*</span>&#0160;<span class="number">1e6</span><br />
<a class="lnum" href="#496" name="496">0496</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">usdouble</span><span class="op">)</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">2.1e6</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;exact&#0160;value&#0160;not&#0160;critical</span><br />
<a class="lnum" href="#497" name="497">0497</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;secondsfrac&#0160;isn't&#0160;referenced&#0160;again</span><br />
<a class="lnum" href="#498" name="498">0498</a><span class="comment"></span><br />
<a class="lnum" href="#499" name="499">0499</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">microseconds</span><span class="op">,</span>&#0160;<span class="name">float</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#500" name="500">0500</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">usdouble</span><br />
<a class="lnum" href="#501" name="501">0501</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">round</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#502" name="502">0502</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span><span class="op">,</span>&#0160;<span class="name">microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">microseconds</span><span class="op">,</span>&#0160;<span class="number">1e6</span><span class="op">)</span><br />
<a class="lnum" href="#503" name="503">0503</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">microseconds</span>&#0160;<span class="op">==</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#504" name="504">0504</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">==</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span><br />
<a class="lnum" href="#505" name="505">0505</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span><span class="op">,</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">seconds</span><span class="op">,</span>&#0160;<span class="number">24.</span><span class="op">*</span><span class="number">3600.</span><span class="op">)</span><br />
<a class="lnum" href="#506" name="506">0506</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">days</span>&#0160;<span class="op">==</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#507" name="507">0507</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">==</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span><br />
<a class="lnum" href="#508" name="508">0508</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">long</span><span class="op">(</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#509" name="509">0509</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span>&#0160;&#0160;&#0160;<span class="comment">#&#0160;can't&#0160;overflow</span><br />
<a class="lnum" href="#510" name="510">0510</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">s</span><span class="op">,</span>&#0160;<span class="name">int</span><span class="op">)</span><br />
<a class="lnum" href="#511" name="511">0511</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">s</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">3</span>&#0160;<span class="op">*</span>&#0160;<span class="number">24</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#512" name="512">0512</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#513" name="513">0513</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span><span class="op">,</span>&#0160;<span class="name">microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">microseconds</span><span class="op">,</span>&#0160;<span class="number">1000000</span><span class="op">)</span><br />
<a class="lnum" href="#514" name="514">0514</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span><span class="op">,</span>&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">seconds</span><span class="op">,</span>&#0160;<span class="number">24</span><span class="op">*</span><span class="number">3600</span><span class="op">)</span><br />
<a class="lnum" href="#515" name="515">0515</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">days</span><br />
<a class="lnum" href="#516" name="516">0516</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">seconds</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;can't&#0160;overflow</span><br />
<a class="lnum" href="#517" name="517">0517</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">s</span><span class="op">,</span>&#0160;<span class="name">int</span><span class="op">)</span><br />
<a class="lnum" href="#518" name="518">0518</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">s</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">3</span>&#0160;<span class="op">*</span>&#0160;<span class="number">24</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#519" name="519">0519</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">float</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#520" name="520">0520</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">usdouble</span><br />
<a class="lnum" href="#521" name="521">0521</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">round</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#522" name="522">0522</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">s</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">3</span>&#0160;<span class="op">*</span>&#0160;<span class="number">24</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#523" name="523">0523</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">3.1e6</span><br />
<a class="lnum" href="#524" name="524">0524</a><br />
<a class="lnum" href="#525" name="525">0525</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Just&#0160;a&#0160;little&#0160;bit&#0160;of&#0160;carrying&#0160;possible&#0160;for&#0160;microseconds&#0160;and&#0160;seconds.</span><br />
<a class="lnum" href="#526" name="526">0526</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">microseconds</span><span class="op">,</span>&#0160;<span class="name">float</span><span class="op">)</span><br />
<a class="lnum" href="#527" name="527">0527</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="name">microseconds</span><br />
<a class="lnum" href="#528" name="528">0528</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us</span>&#0160;<span class="op">=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="name">microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#529" name="529">0529</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span><span class="op">,</span>&#0160;<span class="name">us</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">us</span><span class="op">,</span>&#0160;<span class="number">1000000</span><span class="op">)</span><br />
<a class="lnum" href="#530" name="530">0530</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">seconds</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;cant't&#0160;overflow</span><br />
<a class="lnum" href="#531" name="531">0531</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">s</span><span class="op">,</span>&#0160;<span class="name">int</span><span class="op">)</span><br />
<a class="lnum" href="#532" name="532">0532</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span><span class="op">,</span>&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">s</span><span class="op">,</span>&#0160;<span class="number">24</span><span class="op">*</span><span class="number">3600</span><span class="op">)</span><br />
<a class="lnum" href="#533" name="533">0533</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">d</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">days</span><br />
<a class="lnum" href="#534" name="534">0534</a><br />
<a class="lnum" href="#535" name="535">0535</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">d</span><span class="op">,</span>&#0160;<span class="op">(</span><span class="name">int</span><span class="op">,</span>&#0160;<span class="name">long</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#536" name="536">0536</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">s</span><span class="op">,</span>&#0160;<span class="name">int</span><span class="op">)</span>&#0160;<span class="keyword">and</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">s</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">24</span><span class="op">*</span><span class="number">3600</span><br />
<a class="lnum" href="#537" name="537">0537</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">us</span><span class="op">,</span>&#0160;<span class="name">int</span><span class="op">)</span>&#0160;<span class="keyword">and</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">us</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">1000000</span><br />
<a class="lnum" href="#538" name="538">0538</a><br />
<a class="lnum" href="#539" name="539">0539</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span>&#0160;<span class="op">=</span>&#0160;<span class="name">object</span><span class="op">.</span><span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">)</span><br />
<a class="lnum" href="#540" name="540">0540</a><br />
<a class="lnum" href="#541" name="541">0541</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span>&#0160;<span class="op">=</span>&#0160;<span class="name">d</span><br />
<a class="lnum" href="#542" name="542">0542</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#543" name="543">0543</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">us</span><br />
<a class="lnum" href="#544" name="544">0544</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">d</span><span class="op">)</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">999999999</span><span class="op">:</span><br />
<a class="lnum" href="#545" name="545">0545</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">OverflowError</span><span class="op">(</span><span class="string">"timedelta&#0160;#&#0160;of&#0160;days&#0160;is&#0160;too&#0160;large:&#0160;%d"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">d</span><span class="op">)</span><br />
<a class="lnum" href="#546" name="546">0546</a><br />
<a class="lnum" href="#547" name="547">0547</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#548" name="548">0548</a><br />
<a class="lnum" href="#549" name="549">0549</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__repr__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#550" name="550">0550</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">:</span><br />
<a class="lnum" href="#551" name="551">0551</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="string">"%s(%d,&#0160;%d,&#0160;%d)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="string">'datetime.'</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span><br />
<a class="lnum" href="#552" name="552">0552</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">,</span><br />
<a class="lnum" href="#553" name="553">0553</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">,</span><br />
<a class="lnum" href="#554" name="554">0554</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#555" name="555">0555</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">:</span><br />
<a class="lnum" href="#556" name="556">0556</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="string">"%s(%d,&#0160;%d)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="string">'datetime.'</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span><br />
<a class="lnum" href="#557" name="557">0557</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">,</span><br />
<a class="lnum" href="#558" name="558">0558</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">)</span><br />
<a class="lnum" href="#559" name="559">0559</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="string">"%s(%d)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="string">'datetime.'</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">)</span><br />
<a class="lnum" href="#560" name="560">0560</a><br />
<a class="lnum" href="#561" name="561">0561</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__str__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#562" name="562">0562</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#563" name="563">0563</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">mm</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#564" name="564">0564</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"%d:%02d:%02d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">)</span><br />
<a class="lnum" href="#565" name="565">0565</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">:</span><br />
<a class="lnum" href="#566" name="566">0566</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">plural</span><span class="op">(</span><span class="name">n</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#567" name="567">0567</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">n</span><span class="op">,</span>&#0160;<span class="name">abs</span><span class="op">(</span><span class="name">n</span><span class="op">)</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">1</span>&#0160;<span class="keyword">and</span>&#0160;<span class="string">"s"</span>&#0160;<span class="keyword">or</span>&#0160;<span class="string">""</span><br />
<a class="lnum" href="#568" name="568">0568</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="string">"%d&#0160;day%s,&#0160;"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">plural</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">)</span><span class="op">)</span>&#0160;<span class="op">+</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#569" name="569">0569</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">:</span><br />
<a class="lnum" href="#570" name="570">0570</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">s</span>&#0160;<span class="op">+</span>&#0160;<span class="string">".%06d"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><br />
<a class="lnum" href="#571" name="571">0571</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#572" name="572">0572</a><br />
<a class="lnum" href="#573" name="573">0573</a>&#0160;&#0160;&#0160;&#0160;<span class="name">days</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"days"</span><span class="op">)</span><br />
<a class="lnum" href="#574" name="574">0574</a>&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"seconds"</span><span class="op">)</span><br />
<a class="lnum" href="#575" name="575">0575</a>&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">,</span><br />
<a class="lnum" href="#576" name="576">0576</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"microseconds"</span><span class="op">)</span><br />
<a class="lnum" href="#577" name="577">0577</a><br />
<a class="lnum" href="#578" name="578">0578</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__add__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#579" name="579">0579</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#580" name="580">0580</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;for&#0160;CPython&#0160;compatibility,&#0160;we&#0160;cannot&#0160;use</span><br />
<a class="lnum" href="#581" name="581">0581</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;our&#0160;__class__&#0160;here,&#0160;but&#0160;need&#0160;a&#0160;real&#0160;timedelta</span><br />
<a class="lnum" href="#582" name="582">0582</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__days</span><span class="op">,</span><br />
<a class="lnum" href="#583" name="583">0583</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__seconds</span><span class="op">,</span><br />
<a class="lnum" href="#584" name="584">0584</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#585" name="585">0585</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#586" name="586">0586</a><br />
<a class="lnum" href="#587" name="587">0587</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__radd__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">__add__</span><br />
<a class="lnum" href="#588" name="588">0588</a><br />
<a class="lnum" href="#589" name="589">0589</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__sub__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#590" name="590">0590</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#591" name="591">0591</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span>&#0160;<span class="op">+</span>&#0160;<span class="op">-</span><span class="name">other</span><br />
<a class="lnum" href="#592" name="592">0592</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#593" name="593">0593</a><br />
<a class="lnum" href="#594" name="594">0594</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__rsub__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#595" name="595">0595</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#596" name="596">0596</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">-</span><span class="name">self</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><br />
<a class="lnum" href="#597" name="597">0597</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#598" name="598">0598</a><br />
<a class="lnum" href="#599" name="599">0599</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__neg__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#600" name="600">0600</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;for&#0160;CPython&#0160;compatibility,&#0160;we&#0160;cannot&#0160;use</span><br />
<a class="lnum" href="#601" name="601">0601</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;our&#0160;__class__&#0160;here,&#0160;but&#0160;need&#0160;a&#0160;real&#0160;timedelta</span><br />
<a class="lnum" href="#602" name="602">0602</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="op">-</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">,</span><br />
<a class="lnum" href="#603" name="603">0603</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">-</span><span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">,</span><br />
<a class="lnum" href="#604" name="604">0604</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">-</span><span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#605" name="605">0605</a><br />
<a class="lnum" href="#606" name="606">0606</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__pos__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#607" name="607">0607</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#608" name="608">0608</a><br />
<a class="lnum" href="#609" name="609">0609</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__abs__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#610" name="610">0610</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__days</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#611" name="611">0611</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">-</span><span class="name">self</span><br />
<a class="lnum" href="#612" name="612">0612</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#613" name="613">0613</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#614" name="614">0614</a><br />
<a class="lnum" href="#615" name="615">0615</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__mul__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#616" name="616">0616</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="op">(</span><span class="name">int</span><span class="op">,</span>&#0160;<span class="name">long</span><span class="op">)</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#617" name="617">0617</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;for&#0160;CPython&#0160;compatibility,&#0160;we&#0160;cannot&#0160;use</span><br />
<a class="lnum" href="#618" name="618">0618</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;our&#0160;__class__&#0160;here,&#0160;but&#0160;need&#0160;a&#0160;real&#0160;timedelta</span><br />
<a class="lnum" href="#619" name="619">0619</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span>&#0160;<span class="op">*</span>&#0160;<span class="name">other</span><span class="op">,</span><br />
<a class="lnum" href="#620" name="620">0620</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span>&#0160;<span class="op">*</span>&#0160;<span class="name">other</span><span class="op">,</span><br />
<a class="lnum" href="#621" name="621">0621</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span>&#0160;<span class="op">*</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#622" name="622">0622</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#623" name="623">0623</a><br />
<a class="lnum" href="#624" name="624">0624</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__rmul__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">__mul__</span><br />
<a class="lnum" href="#625" name="625">0625</a><br />
<a class="lnum" href="#626" name="626">0626</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__div__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#627" name="627">0627</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="op">(</span><span class="name">int</span><span class="op">,</span>&#0160;<span class="name">long</span><span class="op">)</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#628" name="628">0628</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">usec</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span>&#0160;<span class="op">*</span>&#0160;<span class="op">(</span><span class="number">24</span><span class="op">*</span><span class="number">3600L</span><span class="op">)</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">)</span>&#0160;<span class="op">*</span>&#0160;<span class="number">1000000</span>&#0160;<span class="op">+</span><br />
<a class="lnum" href="#629" name="629">0629</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#630" name="630">0630</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="name">usec</span>&#0160;<span class="op">//</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#631" name="631">0631</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#632" name="632">0632</a><br />
<a class="lnum" href="#633" name="633">0633</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__floordiv__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">__div__</span><br />
<a class="lnum" href="#634" name="634">0634</a><br />
<a class="lnum" href="#635" name="635">0635</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Comparisons.</span><br />
<a class="lnum" href="#636" name="636">0636</a><span class="comment"></span><br />
<a class="lnum" href="#637" name="637">0637</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__eq__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#638" name="638">0638</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#639" name="639">0639</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#640" name="640">0640</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#641" name="641">0641</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">False</span><br />
<a class="lnum" href="#642" name="642">0642</a><br />
<a class="lnum" href="#643" name="643">0643</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ne__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#644" name="644">0644</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#645" name="645">0645</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#646" name="646">0646</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#647" name="647">0647</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">True</span><br />
<a class="lnum" href="#648" name="648">0648</a><br />
<a class="lnum" href="#649" name="649">0649</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__le__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#650" name="650">0650</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#651" name="651">0651</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#652" name="652">0652</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#653" name="653">0653</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#654" name="654">0654</a><br />
<a class="lnum" href="#655" name="655">0655</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__lt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#656" name="656">0656</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#657" name="657">0657</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#658" name="658">0658</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#659" name="659">0659</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#660" name="660">0660</a><br />
<a class="lnum" href="#661" name="661">0661</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ge__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#662" name="662">0662</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#663" name="663">0663</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#664" name="664">0664</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#665" name="665">0665</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#666" name="666">0666</a><br />
<a class="lnum" href="#667" name="667">0667</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__gt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#668" name="668">0668</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#669" name="669">0669</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#670" name="670">0670</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#671" name="671">0671</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#672" name="672">0672</a><br />
<a class="lnum" href="#673" name="673">0673</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__cmp</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#674" name="674">0674</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><br />
<a class="lnum" href="#675" name="675">0675</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cmp</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#676" name="676">0676</a><br />
<a class="lnum" href="#677" name="677">0677</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__hash__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#678" name="678">0678</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#679" name="679">0679</a><br />
<a class="lnum" href="#680" name="680">0680</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__nonzero__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#681" name="681">0681</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span>&#0160;<span class="keyword">or</span><br />
<a class="lnum" href="#682" name="682">0682</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span>&#0160;<span class="keyword">or</span><br />
<a class="lnum" href="#683" name="683">0683</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><span class="op">)</span><br />
<a class="lnum" href="#684" name="684">0684</a><br />
<a class="lnum" href="#685" name="685">0685</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support.</span><br />
<a class="lnum" href="#686" name="686">0686</a><span class="comment"></span><br />
<a class="lnum" href="#687" name="687">0687</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__safe_for_unpickling__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;For&#0160;Python&#0160;2.2</span><br />
<a class="lnum" href="#688" name="688">0688</a><br />
<a class="lnum" href="#689" name="689">0689</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__getstate</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#690" name="690">0690</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__days</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__seconds</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#691" name="691">0691</a><br />
<a class="lnum" href="#692" name="692">0692</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__reduce__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#693" name="693">0693</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#694" name="694">0694</a><br />
<a class="lnum" href="#695" name="695">0695</a><span class="name">timedelta</span><span class="op">.</span><span class="name">min</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="op">-</span><span class="number">999999999</span><span class="op">)</span><br />
<a class="lnum" href="#696" name="696">0696</a><span class="name">timedelta</span><span class="op">.</span><span class="name">max</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">days</span><span class="op">=</span><span class="number">999999999</span><span class="op">,</span>&#0160;<span class="name">hours</span><span class="op">=</span><span class="number">23</span><span class="op">,</span>&#0160;<span class="name">minutes</span><span class="op">=</span><span class="number">59</span><span class="op">,</span>&#0160;<span class="name">seconds</span><span class="op">=</span><span class="number">59</span><span class="op">,</span><br />
<a class="lnum" href="#697" name="697">0697</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microseconds</span><span class="op">=</span><span class="number">999999</span><span class="op">)</span><br />
<a class="lnum" href="#698" name="698">0698</a><span class="name">timedelta</span><span class="op">.</span><span class="name">resolution</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">microseconds</span><span class="op">=</span><span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#699" name="699">0699</a><br />
<a class="lnum" href="#700" name="700">0700</a><span class="keyword">class</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="name">object</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#701" name="701">0701</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"""Concrete&#0160;date&#0160;type.</span><br />
<a class="lnum" href="#702" name="702">0702</a><span class="string"></span><br />
<a class="lnum" href="#703" name="703">0703</a><span class="string">&#0160;&#0160;&#0160;&#0160;Constructors:</span><br />
<a class="lnum" href="#704" name="704">0704</a><span class="string"></span><br />
<a class="lnum" href="#705" name="705">0705</a><span class="string">&#0160;&#0160;&#0160;&#0160;__new__()</span><br />
<a class="lnum" href="#706" name="706">0706</a><span class="string">&#0160;&#0160;&#0160;&#0160;fromtimestamp()</span><br />
<a class="lnum" href="#707" name="707">0707</a><span class="string">&#0160;&#0160;&#0160;&#0160;today()</span><br />
<a class="lnum" href="#708" name="708">0708</a><span class="string">&#0160;&#0160;&#0160;&#0160;fromordinal()</span><br />
<a class="lnum" href="#709" name="709">0709</a><span class="string"></span><br />
<a class="lnum" href="#710" name="710">0710</a><span class="string">&#0160;&#0160;&#0160;&#0160;Operators:</span><br />
<a class="lnum" href="#711" name="711">0711</a><span class="string"></span><br />
<a class="lnum" href="#712" name="712">0712</a><span class="string">&#0160;&#0160;&#0160;&#0160;__repr__,&#0160;__str__</span><br />
<a class="lnum" href="#713" name="713">0713</a><span class="string">&#0160;&#0160;&#0160;&#0160;__cmp__,&#0160;__hash__</span><br />
<a class="lnum" href="#714" name="714">0714</a><span class="string">&#0160;&#0160;&#0160;&#0160;__add__,&#0160;__radd__,&#0160;__sub__&#0160;(add/radd&#0160;only&#0160;with&#0160;timedelta&#0160;arg)</span><br />
<a class="lnum" href="#715" name="715">0715</a><span class="string"></span><br />
<a class="lnum" href="#716" name="716">0716</a><span class="string">&#0160;&#0160;&#0160;&#0160;Methods:</span><br />
<a class="lnum" href="#717" name="717">0717</a><span class="string"></span><br />
<a class="lnum" href="#718" name="718">0718</a><span class="string">&#0160;&#0160;&#0160;&#0160;timetuple()</span><br />
<a class="lnum" href="#719" name="719">0719</a><span class="string">&#0160;&#0160;&#0160;&#0160;toordinal()</span><br />
<a class="lnum" href="#720" name="720">0720</a><span class="string">&#0160;&#0160;&#0160;&#0160;weekday()</span><br />
<a class="lnum" href="#721" name="721">0721</a><span class="string">&#0160;&#0160;&#0160;&#0160;isoweekday(),&#0160;isocalendar(),&#0160;isoformat()</span><br />
<a class="lnum" href="#722" name="722">0722</a><span class="string">&#0160;&#0160;&#0160;&#0160;ctime()</span><br />
<a class="lnum" href="#723" name="723">0723</a><span class="string">&#0160;&#0160;&#0160;&#0160;strftime()</span><br />
<a class="lnum" href="#724" name="724">0724</a><span class="string"></span><br />
<a class="lnum" href="#725" name="725">0725</a><span class="string">&#0160;&#0160;&#0160;&#0160;Properties&#0160;(readonly):</span><br />
<a class="lnum" href="#726" name="726">0726</a><span class="string">&#0160;&#0160;&#0160;&#0160;year,&#0160;month,&#0160;day</span><br />
<a class="lnum" href="#727" name="727">0727</a><span class="string">&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#728" name="728">0728</a><br />
<a class="lnum" href="#729" name="729">0729</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">=</span><span class="name">None</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#730" name="730">0730</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Constructor.</span><br />
<a class="lnum" href="#731" name="731">0731</a><span class="string"></span><br />
<a class="lnum" href="#732" name="732">0732</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;Arguments:</span><br />
<a class="lnum" href="#733" name="733">0733</a><span class="string"></span><br />
<a class="lnum" href="#734" name="734">0734</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;year,&#0160;month,&#0160;day&#0160;(required,&#0160;base&#0160;1)</span><br />
<a class="lnum" href="#735" name="735">0735</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#736" name="736">0736</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">str</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#737" name="737">0737</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support</span><br />
<a class="lnum" href="#738" name="738">0738</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span>&#0160;<span class="op">=</span>&#0160;<span class="name">object</span><span class="op">.</span><span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">)</span><br />
<a class="lnum" href="#739" name="739">0739</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__setstate</span><span class="op">(</span><span class="op">(</span><span class="name">year</span><span class="op">,</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#740" name="740">0740</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#741" name="741">0741</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_date_fields</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#742" name="742">0742</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span>&#0160;<span class="op">=</span>&#0160;<span class="name">object</span><span class="op">.</span><span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">)</span><br />
<a class="lnum" href="#743" name="743">0743</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">year</span><br />
<a class="lnum" href="#744" name="744">0744</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span>&#0160;<span class="op">=</span>&#0160;<span class="name">month</span><br />
<a class="lnum" href="#745" name="745">0745</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">day</span><br />
<a class="lnum" href="#746" name="746">0746</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#747" name="747">0747</a><br />
<a class="lnum" href="#748" name="748">0748</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Additional&#0160;constructors</span><br />
<a class="lnum" href="#749" name="749">0749</a><span class="comment"></span><br />
<a class="lnum" href="#750" name="750">0750</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">fromtimestamp</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#751" name="751">0751</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Construct&#0160;a&#0160;date&#0160;from&#0160;a&#0160;POSIX&#0160;timestamp&#0160;(like&#0160;time.time())."</span><br />
<a class="lnum" href="#752" name="752">0752</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">weekday</span><span class="op">,</span>&#0160;<span class="name">jday</span><span class="op">,</span>&#0160;<span class="name">dst</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">localtime</span><span class="op">(</span><span class="name">t</span><span class="op">)</span><br />
<a class="lnum" href="#753" name="753">0753</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">)</span><br />
<a class="lnum" href="#754" name="754">0754</a>&#0160;&#0160;&#0160;&#0160;<span class="name">fromtimestamp</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">fromtimestamp</span><span class="op">)</span><br />
<a class="lnum" href="#755" name="755">0755</a><br />
<a class="lnum" href="#756" name="756">0756</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">today</span><span class="op">(</span><span class="name">cls</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#757" name="757">0757</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Construct&#0160;a&#0160;date&#0160;from&#0160;time.time()."</span><br />
<a class="lnum" href="#758" name="758">0758</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">time</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#759" name="759">0759</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">.</span><span class="name">fromtimestamp</span><span class="op">(</span><span class="name">t</span><span class="op">)</span><br />
<a class="lnum" href="#760" name="760">0760</a>&#0160;&#0160;&#0160;&#0160;<span class="name">today</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">today</span><span class="op">)</span><br />
<a class="lnum" href="#761" name="761">0761</a><br />
<a class="lnum" href="#762" name="762">0762</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">fromordinal</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">n</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#763" name="763">0763</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Contruct&#0160;a&#0160;date&#0160;from&#0160;a&#0160;proleptic&#0160;Gregorian&#0160;ordinal.</span><br />
<a class="lnum" href="#764" name="764">0764</a><span class="string"></span><br />
<a class="lnum" href="#765" name="765">0765</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;January&#0160;1&#0160;of&#0160;year&#0160;1&#0160;is&#0160;day&#0160;1.&#0160;&#0160;Only&#0160;the&#0160;year,&#0160;month&#0160;and&#0160;day&#0160;are</span><br />
<a class="lnum" href="#766" name="766">0766</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;non-zero&#0160;in&#0160;the&#0160;result.</span><br />
<a class="lnum" href="#767" name="767">0767</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#768" name="768">0768</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ord2ymd</span><span class="op">(</span><span class="name">n</span><span class="op">)</span><br />
<a class="lnum" href="#769" name="769">0769</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">)</span><br />
<a class="lnum" href="#770" name="770">0770</a>&#0160;&#0160;&#0160;&#0160;<span class="name">fromordinal</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">fromordinal</span><span class="op">)</span><br />
<a class="lnum" href="#771" name="771">0771</a><br />
<a class="lnum" href="#772" name="772">0772</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Conversions&#0160;to&#0160;string</span><br />
<a class="lnum" href="#773" name="773">0773</a><span class="comment"></span><br />
<a class="lnum" href="#774" name="774">0774</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__repr__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#775" name="775">0775</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Convert&#0160;to&#0160;formal&#0160;string,&#0160;for&#0160;repr()."</span><br />
<a class="lnum" href="#776" name="776">0776</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="string">"%s(%d,&#0160;%d,&#0160;%d)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="string">'datetime.'</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span><br />
<a class="lnum" href="#777" name="777">0777</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span><br />
<a class="lnum" href="#778" name="778">0778</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span><br />
<a class="lnum" href="#779" name="779">0779</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><br />
<a class="lnum" href="#780" name="780">0780</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;These&#0160;shouldn't&#0160;depend&#0160;on&#0160;time.localtime(),&#0160;because&#0160;that</span><br />
<a class="lnum" href="#781" name="781">0781</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;clips&#0160;the&#0160;usable&#0160;dates&#0160;to&#0160;[1970&#0160;..&#0160;2038).&#0160;&#0160;At&#0160;least&#0160;ctime()&#0160;is</span><br />
<a class="lnum" href="#782" name="782">0782</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;easily&#0160;done&#0160;without&#0160;using&#0160;strftime()&#0160;--&#0160;that's&#0160;better&#0160;too&#0160;because</span><br />
<a class="lnum" href="#783" name="783">0783</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;strftime("%c",&#0160;...)&#0160;is&#0160;locale&#0160;specific.</span><br />
<a class="lnum" href="#784" name="784">0784</a><span class="comment"></span><br />
<a class="lnum" href="#785" name="785">0785</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">ctime</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#786" name="786">0786</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Format&#0160;a&#0160;la&#0160;ctime()."</span><br />
<a class="lnum" href="#787" name="787">0787</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">tmxxx</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><span class="op">.</span><span class="name">ctime</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#788" name="788">0788</a><br />
<a class="lnum" href="#789" name="789">0789</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">strftime</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">fmt</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#790" name="790">0790</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Format&#0160;using&#0160;strftime()."</span><br />
<a class="lnum" href="#791" name="791">0791</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_wrap_strftime</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">fmt</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">timetuple</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#792" name="792">0792</a><br />
<a class="lnum" href="#793" name="793">0793</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">isoformat</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#794" name="794">0794</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;date&#0160;formatted&#0160;according&#0160;to&#0160;ISO.</span><br />
<a class="lnum" href="#795" name="795">0795</a><span class="string"></span><br />
<a class="lnum" href="#796" name="796">0796</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;This&#0160;is&#0160;'YYYY-MM-DD'.</span><br />
<a class="lnum" href="#797" name="797">0797</a><span class="string"></span><br />
<a class="lnum" href="#798" name="798">0798</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;References:</span><br />
<a class="lnum" href="#799" name="799">0799</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-&#0160;http://www.w3.org/TR/NOTE-datetime</span><br />
<a class="lnum" href="#800" name="800">0800</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-&#0160;http://www.cl.cam.ac.uk/~mgk25/iso-time.html</span><br />
<a class="lnum" href="#801" name="801">0801</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#802" name="802">0802</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="string">"%04d-%02d-%02d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><br />
<a class="lnum" href="#803" name="803">0803</a><br />
<a class="lnum" href="#804" name="804">0804</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__str__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">isoformat</span><br />
<a class="lnum" href="#805" name="805">0805</a><br />
<a class="lnum" href="#806" name="806">0806</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Read-only&#0160;field&#0160;accessors</span><br />
<a class="lnum" href="#807" name="807">0807</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span><br />
<a class="lnum" href="#808" name="808">0808</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"year&#0160;(%d-%d)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">MINYEAR</span><span class="op">,</span>&#0160;<span class="name">MAXYEAR</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#809" name="809">0809</a>&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"month&#0160;(1-12)"</span><span class="op">)</span><br />
<a class="lnum" href="#810" name="810">0810</a>&#0160;&#0160;&#0160;&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"day&#0160;(1-31)"</span><span class="op">)</span><br />
<a class="lnum" href="#811" name="811">0811</a><br />
<a class="lnum" href="#812" name="812">0812</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Standard&#0160;conversions,&#0160;__cmp__,&#0160;__hash__&#0160;(and&#0160;helpers)</span><br />
<a class="lnum" href="#813" name="813">0813</a><span class="comment"></span><br />
<a class="lnum" href="#814" name="814">0814</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">timetuple</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#815" name="815">0815</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;local&#0160;time&#0160;tuple&#0160;compatible&#0160;with&#0160;time.localtime()."</span><br />
<a class="lnum" href="#816" name="816">0816</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_build_struct_time</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span><br />
<a class="lnum" href="#817" name="817">0817</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="op">-</span><span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#818" name="818">0818</a><br />
<a class="lnum" href="#819" name="819">0819</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">toordinal</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#820" name="820">0820</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;proleptic&#0160;Gregorian&#0160;ordinal&#0160;for&#0160;the&#0160;year,&#0160;month&#0160;and&#0160;day.</span><br />
<a class="lnum" href="#821" name="821">0821</a><span class="string"></span><br />
<a class="lnum" href="#822" name="822">0822</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;January&#0160;1&#0160;of&#0160;year&#0160;1&#0160;is&#0160;day&#0160;1.&#0160;&#0160;Only&#0160;the&#0160;year,&#0160;month&#0160;and&#0160;day&#0160;values</span><br />
<a class="lnum" href="#823" name="823">0823</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;contribute&#0160;to&#0160;the&#0160;result.</span><br />
<a class="lnum" href="#824" name="824">0824</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#825" name="825">0825</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><br />
<a class="lnum" href="#826" name="826">0826</a><br />
<a class="lnum" href="#827" name="827">0827</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">replace</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">=</span><span class="name">None</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#828" name="828">0828</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;a&#0160;new&#0160;date&#0160;with&#0160;new&#0160;values&#0160;for&#0160;the&#0160;specified&#0160;fields."""</span><br />
<a class="lnum" href="#829" name="829">0829</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">year</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#830" name="830">0830</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span><br />
<a class="lnum" href="#831" name="831">0831</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">month</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#832" name="832">0832</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><br />
<a class="lnum" href="#833" name="833">0833</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">day</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#834" name="834">0834</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><br />
<a class="lnum" href="#835" name="835">0835</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_date_fields</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#836" name="836">0836</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#837" name="837">0837</a><br />
<a class="lnum" href="#838" name="838">0838</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Comparisons.</span><br />
<a class="lnum" href="#839" name="839">0839</a><span class="comment"></span><br />
<a class="lnum" href="#840" name="840">0840</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__eq__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#841" name="841">0841</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#842" name="842">0842</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#843" name="843">0843</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#844" name="844">0844</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#845" name="845">0845</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#846" name="846">0846</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">False</span><br />
<a class="lnum" href="#847" name="847">0847</a><br />
<a class="lnum" href="#848" name="848">0848</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ne__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#849" name="849">0849</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#850" name="850">0850</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#851" name="851">0851</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#852" name="852">0852</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#853" name="853">0853</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#854" name="854">0854</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">True</span><br />
<a class="lnum" href="#855" name="855">0855</a><br />
<a class="lnum" href="#856" name="856">0856</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__le__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#857" name="857">0857</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#858" name="858">0858</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#859" name="859">0859</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#860" name="860">0860</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#861" name="861">0861</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#862" name="862">0862</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#863" name="863">0863</a><br />
<a class="lnum" href="#864" name="864">0864</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__lt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#865" name="865">0865</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#866" name="866">0866</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#867" name="867">0867</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#868" name="868">0868</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#869" name="869">0869</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#870" name="870">0870</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#871" name="871">0871</a><br />
<a class="lnum" href="#872" name="872">0872</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ge__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#873" name="873">0873</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#874" name="874">0874</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#875" name="875">0875</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#876" name="876">0876</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#877" name="877">0877</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#878" name="878">0878</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#879" name="879">0879</a><br />
<a class="lnum" href="#880" name="880">0880</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__gt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#881" name="881">0881</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#882" name="882">0882</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#883" name="883">0883</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#884" name="884">0884</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#885" name="885">0885</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#886" name="886">0886</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#887" name="887">0887</a><br />
<a class="lnum" href="#888" name="888">0888</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__cmp</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#889" name="889">0889</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><br />
<a class="lnum" href="#890" name="890">0890</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><br />
<a class="lnum" href="#891" name="891">0891</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y2</span><span class="op">,</span>&#0160;<span class="name">m2</span><span class="op">,</span>&#0160;<span class="name">d2</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__day</span><br />
<a class="lnum" href="#892" name="892">0892</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cmp</span><span class="op">(</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">)</span><span class="op">,</span>&#0160;<span class="op">(</span><span class="name">y2</span><span class="op">,</span>&#0160;<span class="name">m2</span><span class="op">,</span>&#0160;<span class="name">d2</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#893" name="893">0893</a><br />
<a class="lnum" href="#894" name="894">0894</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__hash__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#895" name="895">0895</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Hash."</span><br />
<a class="lnum" href="#896" name="896">0896</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#897" name="897">0897</a><br />
<a class="lnum" href="#898" name="898">0898</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Computations</span><br />
<a class="lnum" href="#899" name="899">0899</a><span class="comment"></span><br />
<a class="lnum" href="#900" name="900">0900</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">_checkOverflow</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#901" name="901">0901</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">MINYEAR</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">year</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">MAXYEAR</span><span class="op">:</span><br />
<a class="lnum" href="#902" name="902">0902</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">OverflowError</span><span class="op">(</span><span class="string">"date&#0160;+/-:&#0160;result&#0160;year&#0160;%d&#0160;not&#0160;in&#0160;%d..%d"</span>&#0160;<span class="op">%</span><br />
<a class="lnum" href="#903" name="903">0903</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">MINYEAR</span><span class="op">,</span>&#0160;<span class="name">MAXYEAR</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#904" name="904">0904</a><br />
<a class="lnum" href="#905" name="905">0905</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__add__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#906" name="906">0906</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Add&#0160;a&#0160;date&#0160;to&#0160;a&#0160;timedelta."</span><br />
<a class="lnum" href="#907" name="907">0907</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#908" name="908">0908</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tmxxx</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span><br />
<a class="lnum" href="#909" name="909">0909</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span><br />
<a class="lnum" href="#910" name="910">0910</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#911" name="911">0911</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_checkOverflow</span><span class="op">(</span><span class="name">t</span><span class="op">.</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#912" name="912">0912</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">result</span>&#0160;<span class="op">=</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="name">t</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#913" name="913">0913</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">result</span><br />
<a class="lnum" href="#914" name="914">0914</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><br />
<a class="lnum" href="#915" name="915">0915</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;Should&#0160;be&#0160;'return&#0160;NotImplemented',&#0160;but&#0160;there's&#0160;a&#0160;bug&#0160;in&#0160;2.2...</span><br />
<a class="lnum" href="#916" name="916">0916</a><span class="comment"></span><br />
<a class="lnum" href="#917" name="917">0917</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__radd__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">__add__</span><br />
<a class="lnum" href="#918" name="918">0918</a><br />
<a class="lnum" href="#919" name="919">0919</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__sub__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#920" name="920">0920</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Subtract&#0160;two&#0160;dates,&#0160;or&#0160;a&#0160;date&#0160;and&#0160;a&#0160;timedelta."""</span><br />
<a class="lnum" href="#921" name="921">0921</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#922" name="922">0922</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span>&#0160;<span class="op">+</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="op">-</span><span class="name">other</span><span class="op">.</span><span class="name">days</span><span class="op">)</span><br />
<a class="lnum" href="#923" name="923">0923</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#924" name="924">0924</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days1</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#925" name="925">0925</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days2</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#926" name="926">0926</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">days1</span>&#0160;<span class="op">-</span>&#0160;<span class="name">days2</span><span class="op">)</span><br />
<a class="lnum" href="#927" name="927">0927</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#928" name="928">0928</a><br />
<a class="lnum" href="#929" name="929">0929</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">weekday</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#930" name="930">0930</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;day&#0160;of&#0160;the&#0160;week,&#0160;where&#0160;Monday&#0160;==&#0160;0&#0160;...&#0160;Sunday&#0160;==&#0160;6."</span><br />
<a class="lnum" href="#931" name="931">0931</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span>&#0160;<span class="op">+</span>&#0160;<span class="number">6</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="number">7</span><br />
<a class="lnum" href="#932" name="932">0932</a><br />
<a class="lnum" href="#933" name="933">0933</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Day-of-the-week&#0160;and&#0160;week-of-the-year,&#0160;according&#0160;to&#0160;ISO</span><br />
<a class="lnum" href="#934" name="934">0934</a><span class="comment"></span><br />
<a class="lnum" href="#935" name="935">0935</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">isoweekday</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#936" name="936">0936</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;day&#0160;of&#0160;the&#0160;week,&#0160;where&#0160;Monday&#0160;==&#0160;1&#0160;...&#0160;Sunday&#0160;==&#0160;7."</span><br />
<a class="lnum" href="#937" name="937">0937</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;1-Jan-0001&#0160;is&#0160;a&#0160;Monday</span><br />
<a class="lnum" href="#938" name="938">0938</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="number">7</span>&#0160;<span class="keyword">or</span>&#0160;<span class="number">7</span><br />
<a class="lnum" href="#939" name="939">0939</a><br />
<a class="lnum" href="#940" name="940">0940</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">isocalendar</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#941" name="941">0941</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;a&#0160;3-tuple&#0160;containing&#0160;ISO&#0160;year,&#0160;week&#0160;number,&#0160;and&#0160;weekday.</span><br />
<a class="lnum" href="#942" name="942">0942</a><span class="string"></span><br />
<a class="lnum" href="#943" name="943">0943</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;The&#0160;first&#0160;ISO&#0160;week&#0160;of&#0160;the&#0160;year&#0160;is&#0160;the&#0160;(Mon-Sun)&#0160;week</span><br />
<a class="lnum" href="#944" name="944">0944</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;containing&#0160;the&#0160;year's&#0160;first&#0160;Thursday;&#0160;everything&#0160;else&#0160;derives</span><br />
<a class="lnum" href="#945" name="945">0945</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;from&#0160;that.</span><br />
<a class="lnum" href="#946" name="946">0946</a><span class="string"></span><br />
<a class="lnum" href="#947" name="947">0947</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;The&#0160;first&#0160;week&#0160;is&#0160;1;&#0160;Monday&#0160;is&#0160;1&#0160;...&#0160;Sunday&#0160;is&#0160;7.</span><br />
<a class="lnum" href="#948" name="948">0948</a><span class="string"></span><br />
<a class="lnum" href="#949" name="949">0949</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;ISO&#0160;calendar&#0160;algorithm&#0160;taken&#0160;from</span><br />
<a class="lnum" href="#950" name="950">0950</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm</span><br />
<a class="lnum" href="#951" name="951">0951</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#952" name="952">0952</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span><br />
<a class="lnum" href="#953" name="953">0953</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">week1monday</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_isoweek1monday</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#954" name="954">0954</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">today</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><br />
<a class="lnum" href="#955" name="955">0955</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Internally,&#0160;week&#0160;and&#0160;day&#0160;have&#0160;origin&#0160;0</span><br />
<a class="lnum" href="#956" name="956">0956</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">week</span><span class="op">,</span>&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">today</span>&#0160;<span class="op">-</span>&#0160;<span class="name">week1monday</span><span class="op">,</span>&#0160;<span class="number">7</span><span class="op">)</span><br />
<a class="lnum" href="#957" name="957">0957</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">week</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#958" name="958">0958</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">-=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#959" name="959">0959</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">week1monday</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_isoweek1monday</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#960" name="960">0960</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">week</span><span class="op">,</span>&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">today</span>&#0160;<span class="op">-</span>&#0160;<span class="name">week1monday</span><span class="op">,</span>&#0160;<span class="number">7</span><span class="op">)</span><br />
<a class="lnum" href="#961" name="961">0961</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">week</span>&#0160;<span class="op">&gt;=</span>&#0160;<span class="number">52</span><span class="op">:</span><br />
<a class="lnum" href="#962" name="962">0962</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">today</span>&#0160;<span class="op">&gt;=</span>&#0160;<span class="name">_isoweek1monday</span><span class="op">(</span><span class="name">year</span><span class="op">+</span><span class="number">1</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#963" name="963">0963</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#964" name="964">0964</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">week</span>&#0160;<span class="op">=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#965" name="965">0965</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">week</span><span class="op">+</span><span class="number">1</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">+</span><span class="number">1</span><br />
<a class="lnum" href="#966" name="966">0966</a><br />
<a class="lnum" href="#967" name="967">0967</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support.</span><br />
<a class="lnum" href="#968" name="968">0968</a><span class="comment"></span><br />
<a class="lnum" href="#969" name="969">0969</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__safe_for_unpickling__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;For&#0160;Python&#0160;2.2</span><br />
<a class="lnum" href="#970" name="970">0970</a><br />
<a class="lnum" href="#971" name="971">0971</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__getstate</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#972" name="972">0972</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">yhi</span><span class="op">,</span>&#0160;<span class="name">ylo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="number">256</span><span class="op">)</span><br />
<a class="lnum" href="#973" name="973">0973</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="string">"%c%c%c%c"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">yhi</span><span class="op">,</span>&#0160;<span class="name">ylo</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><span class="op">,</span>&#0160;<span class="op">)</span><br />
<a class="lnum" href="#974" name="974">0974</a><br />
<a class="lnum" href="#975" name="975">0975</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__setstate</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#976" name="976">0976</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">t</span><span class="op">,</span>&#0160;<span class="name">tuple</span><span class="op">)</span>&#0160;<span class="keyword">and</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">t</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="op">`</span><span class="name">t</span><span class="op">`</span><br />
<a class="lnum" href="#977" name="977">0977</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">string</span>&#0160;<span class="op">=</span>&#0160;<span class="name">t</span><span class="op">[</span><span class="number">0</span><span class="op">]</span><br />
<a class="lnum" href="#978" name="978">0978</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">string</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">4</span><br />
<a class="lnum" href="#979" name="979">0979</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">yhi</span><span class="op">,</span>&#0160;<span class="name">ylo</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">map</span><span class="op">(</span><span class="name">ord</span><span class="op">,</span>&#0160;<span class="name">string</span><span class="op">)</span><br />
<a class="lnum" href="#980" name="980">0980</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">yhi</span>&#0160;<span class="op">*</span>&#0160;<span class="number">256</span>&#0160;<span class="op">+</span>&#0160;<span class="name">ylo</span><br />
<a class="lnum" href="#981" name="981">0981</a><br />
<a class="lnum" href="#982" name="982">0982</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__reduce__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#983" name="983">0983</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#984" name="984">0984</a><br />
<a class="lnum" href="#985" name="985">0985</a><span class="name">_date_class</span>&#0160;<span class="op">=</span>&#0160;<span class="name">date</span>&#0160;&#0160;<span class="comment">#&#0160;so&#0160;functions&#0160;w/&#0160;args&#0160;named&#0160;"date"&#0160;can&#0160;get&#0160;at&#0160;the&#0160;class</span><br />
<a class="lnum" href="#986" name="986">0986</a><br />
<a class="lnum" href="#987" name="987">0987</a><span class="name">date</span><span class="op">.</span><span class="name">min</span>&#0160;<span class="op">=</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#988" name="988">0988</a><span class="name">date</span><span class="op">.</span><span class="name">max</span>&#0160;<span class="op">=</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="number">9999</span><span class="op">,</span>&#0160;<span class="number">12</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">)</span><br />
<a class="lnum" href="#989" name="989">0989</a><span class="name">date</span><span class="op">.</span><span class="name">resolution</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">days</span><span class="op">=</span><span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#990" name="990">0990</a><br />
<a class="lnum" href="#991" name="991">0991</a><span class="keyword">class</span>&#0160;<span class="name">tzinfo</span><span class="op">(</span><span class="name">object</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#992" name="992">0992</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"""Abstract&#0160;base&#0160;class&#0160;for&#0160;time&#0160;zone&#0160;info&#0160;classes.</span><br />
<a class="lnum" href="#993" name="993">0993</a><span class="string"></span><br />
<a class="lnum" href="#994" name="994">0994</a><span class="string">&#0160;&#0160;&#0160;&#0160;Subclasses&#0160;must&#0160;override&#0160;the&#0160;name(),&#0160;utcoffset()&#0160;and&#0160;dst()&#0160;methods.</span><br />
<a class="lnum" href="#995" name="995">0995</a><span class="string">&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#996" name="996">0996</a><br />
<a class="lnum" href="#997" name="997">0997</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">tzname</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">dt</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#998" name="998">0998</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"datetime&#0160;-&gt;&#0160;string&#0160;name&#0160;of&#0160;time&#0160;zone."</span><br />
<a class="lnum" href="#999" name="999">0999</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">NotImplementedError</span><span class="op">(</span><span class="string">"tzinfo&#0160;subclass&#0160;must&#0160;override&#0160;tzname()"</span><span class="op">)</span><br />
<a class="lnum" href="#1000" name="1000">1000</a><br />
<a class="lnum" href="#1001" name="1001">1001</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">utcoffset</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">dt</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1002" name="1002">1002</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"datetime&#0160;-&gt;&#0160;minutes&#0160;east&#0160;of&#0160;UTC&#0160;(negative&#0160;for&#0160;west&#0160;of&#0160;UTC)"</span><br />
<a class="lnum" href="#1003" name="1003">1003</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">NotImplementedError</span><span class="op">(</span><span class="string">"tzinfo&#0160;subclass&#0160;must&#0160;override&#0160;utcoffset()"</span><span class="op">)</span><br />
<a class="lnum" href="#1004" name="1004">1004</a><br />
<a class="lnum" href="#1005" name="1005">1005</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">dst</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">dt</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1006" name="1006">1006</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""datetime&#0160;-&gt;&#0160;DST&#0160;offset&#0160;in&#0160;minutes&#0160;east&#0160;of&#0160;UTC.</span><br />
<a class="lnum" href="#1007" name="1007">1007</a><span class="string"></span><br />
<a class="lnum" href="#1008" name="1008">1008</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;Return&#0160;0&#0160;if&#0160;DST&#0160;not&#0160;in&#0160;effect.&#0160;&#0160;utcoffset()&#0160;must&#0160;include&#0160;the&#0160;DST</span><br />
<a class="lnum" href="#1009" name="1009">1009</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;offset.</span><br />
<a class="lnum" href="#1010" name="1010">1010</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1011" name="1011">1011</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">NotImplementedError</span><span class="op">(</span><span class="string">"tzinfo&#0160;subclass&#0160;must&#0160;override&#0160;dst()"</span><span class="op">)</span><br />
<a class="lnum" href="#1012" name="1012">1012</a><br />
<a class="lnum" href="#1013" name="1013">1013</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">fromutc</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">dt</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1014" name="1014">1014</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"datetime&#0160;in&#0160;UTC&#0160;-&gt;&#0160;datetime&#0160;in&#0160;local&#0160;time."</span><br />
<a class="lnum" href="#1015" name="1015">1015</a><br />
<a class="lnum" href="#1016" name="1016">1016</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">dt</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1017" name="1017">1017</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"fromutc()&#0160;requires&#0160;a&#0160;datetime&#0160;argument"</span><span class="op">)</span><br />
<a class="lnum" href="#1018" name="1018">1018</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">dt</span><span class="op">.</span><span class="name">tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">self</span><span class="op">:</span><br />
<a class="lnum" href="#1019" name="1019">1019</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"dt.tzinfo&#0160;is&#0160;not&#0160;self"</span><span class="op">)</span><br />
<a class="lnum" href="#1020" name="1020">1020</a><br />
<a class="lnum" href="#1021" name="1021">1021</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dtoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">dt</span><span class="op">.</span><span class="name">utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1022" name="1022">1022</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">dtoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1023" name="1023">1023</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"fromutc()&#0160;requires&#0160;a&#0160;non-None&#0160;utcoffset()&#0160;"</span><br />
<a class="lnum" href="#1024" name="1024">1024</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"result"</span><span class="op">)</span><br />
<a class="lnum" href="#1025" name="1025">1025</a><br />
<a class="lnum" href="#1026" name="1026">1026</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;See&#0160;the&#0160;long&#0160;comment&#0160;block&#0160;at&#0160;the&#0160;end&#0160;of&#0160;this&#0160;file&#0160;for&#0160;an</span><br />
<a class="lnum" href="#1027" name="1027">1027</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;explanation&#0160;of&#0160;this&#0160;algorithm.</span><br />
<a class="lnum" href="#1028" name="1028">1028</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dtdst</span>&#0160;<span class="op">=</span>&#0160;<span class="name">dt</span><span class="op">.</span><span class="name">dst</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1029" name="1029">1029</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">dtdst</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1030" name="1030">1030</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"fromutc()&#0160;requires&#0160;a&#0160;non-None&#0160;dst()&#0160;result"</span><span class="op">)</span><br />
<a class="lnum" href="#1031" name="1031">1031</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">delta</span>&#0160;<span class="op">=</span>&#0160;<span class="name">dtoff</span>&#0160;<span class="op">-</span>&#0160;<span class="name">dtdst</span><br />
<a class="lnum" href="#1032" name="1032">1032</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">delta</span><span class="op">:</span><br />
<a class="lnum" href="#1033" name="1033">1033</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dt</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">delta</span><br />
<a class="lnum" href="#1034" name="1034">1034</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dtdst</span>&#0160;<span class="op">=</span>&#0160;<span class="name">dt</span><span class="op">.</span><span class="name">dst</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1035" name="1035">1035</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">dtdst</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1036" name="1036">1036</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"fromutc():&#0160;dt.dst&#0160;gave&#0160;inconsistent&#0160;"</span><br />
<a class="lnum" href="#1037" name="1037">1037</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"results;&#0160;cannot&#0160;convert"</span><span class="op">)</span><br />
<a class="lnum" href="#1038" name="1038">1038</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">dtdst</span><span class="op">:</span><br />
<a class="lnum" href="#1039" name="1039">1039</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">dt</span>&#0160;<span class="op">+</span>&#0160;<span class="name">dtdst</span><br />
<a class="lnum" href="#1040" name="1040">1040</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1041" name="1041">1041</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">dt</span><br />
<a class="lnum" href="#1042" name="1042">1042</a><br />
<a class="lnum" href="#1043" name="1043">1043</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support.</span><br />
<a class="lnum" href="#1044" name="1044">1044</a><span class="comment"></span><br />
<a class="lnum" href="#1045" name="1045">1045</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__safe_for_unpickling__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;For&#0160;Python&#0160;2.2</span><br />
<a class="lnum" href="#1046" name="1046">1046</a><br />
<a class="lnum" href="#1047" name="1047">1047</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__reduce__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1048" name="1048">1048</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">getinitargs</span>&#0160;<span class="op">=</span>&#0160;<span class="name">getattr</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="string">"__getinitargs__"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1049" name="1049">1049</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">getinitargs</span><span class="op">:</span><br />
<a class="lnum" href="#1050" name="1050">1050</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">args</span>&#0160;<span class="op">=</span>&#0160;<span class="name">getinitargs</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1051" name="1051">1051</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1052" name="1052">1052</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">args</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1053" name="1053">1053</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">getstate</span>&#0160;<span class="op">=</span>&#0160;<span class="name">getattr</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="string">"__getstate__"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1054" name="1054">1054</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">getstate</span><span class="op">:</span><br />
<a class="lnum" href="#1055" name="1055">1055</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">state</span>&#0160;<span class="op">=</span>&#0160;<span class="name">getstate</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1056" name="1056">1056</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1057" name="1057">1057</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">state</span>&#0160;<span class="op">=</span>&#0160;<span class="name">getattr</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="string">"__dict__"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#1058" name="1058">1058</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">state</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1059" name="1059">1059</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">,</span>&#0160;<span class="name">args</span><span class="op">)</span><br />
<a class="lnum" href="#1060" name="1060">1060</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1061" name="1061">1061</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">,</span>&#0160;<span class="name">args</span><span class="op">,</span>&#0160;<span class="name">state</span><span class="op">)</span><br />
<a class="lnum" href="#1062" name="1062">1062</a><br />
<a class="lnum" href="#1063" name="1063">1063</a><span class="name">_tzinfo_class</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tzinfo</span>&#0160;&#0160;&#0160;<span class="comment">#&#0160;so&#0160;functions&#0160;w/&#0160;args&#0160;named&#0160;"tinfo"&#0160;can&#0160;get&#0160;at&#0160;it</span><br />
<a class="lnum" href="#1064" name="1064">1064</a><br />
<a class="lnum" href="#1065" name="1065">1065</a><span class="keyword">class</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="name">object</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1066" name="1066">1066</a>&#0160;&#0160;&#0160;&#0160;<span class="string">"""Time&#0160;with&#0160;time&#0160;zone.</span><br />
<a class="lnum" href="#1067" name="1067">1067</a><span class="string"></span><br />
<a class="lnum" href="#1068" name="1068">1068</a><span class="string">&#0160;&#0160;&#0160;&#0160;Constructors:</span><br />
<a class="lnum" href="#1069" name="1069">1069</a><span class="string"></span><br />
<a class="lnum" href="#1070" name="1070">1070</a><span class="string">&#0160;&#0160;&#0160;&#0160;__new__()</span><br />
<a class="lnum" href="#1071" name="1071">1071</a><span class="string"></span><br />
<a class="lnum" href="#1072" name="1072">1072</a><span class="string">&#0160;&#0160;&#0160;&#0160;Operators:</span><br />
<a class="lnum" href="#1073" name="1073">1073</a><span class="string"></span><br />
<a class="lnum" href="#1074" name="1074">1074</a><span class="string">&#0160;&#0160;&#0160;&#0160;__repr__,&#0160;__str__</span><br />
<a class="lnum" href="#1075" name="1075">1075</a><span class="string">&#0160;&#0160;&#0160;&#0160;__cmp__,&#0160;__hash__</span><br />
<a class="lnum" href="#1076" name="1076">1076</a><span class="string"></span><br />
<a class="lnum" href="#1077" name="1077">1077</a><span class="string">&#0160;&#0160;&#0160;&#0160;Methods:</span><br />
<a class="lnum" href="#1078" name="1078">1078</a><span class="string"></span><br />
<a class="lnum" href="#1079" name="1079">1079</a><span class="string">&#0160;&#0160;&#0160;&#0160;strftime()</span><br />
<a class="lnum" href="#1080" name="1080">1080</a><span class="string">&#0160;&#0160;&#0160;&#0160;isoformat()</span><br />
<a class="lnum" href="#1081" name="1081">1081</a><span class="string">&#0160;&#0160;&#0160;&#0160;utcoffset()</span><br />
<a class="lnum" href="#1082" name="1082">1082</a><span class="string">&#0160;&#0160;&#0160;&#0160;tzname()</span><br />
<a class="lnum" href="#1083" name="1083">1083</a><span class="string">&#0160;&#0160;&#0160;&#0160;dst()</span><br />
<a class="lnum" href="#1084" name="1084">1084</a><span class="string"></span><br />
<a class="lnum" href="#1085" name="1085">1085</a><span class="string">&#0160;&#0160;&#0160;&#0160;Properties&#0160;(readonly):</span><br />
<a class="lnum" href="#1086" name="1086">1086</a><span class="string">&#0160;&#0160;&#0160;&#0160;hour,&#0160;minute,&#0160;second,&#0160;microsecond,&#0160;tzinfo</span><br />
<a class="lnum" href="#1087" name="1087">1087</a><span class="string">&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1088" name="1088">1088</a><br />
<a class="lnum" href="#1089" name="1089">1089</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">=</span><span class="name">None</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1090" name="1090">1090</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Constructor.</span><br />
<a class="lnum" href="#1091" name="1091">1091</a><span class="string"></span><br />
<a class="lnum" href="#1092" name="1092">1092</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;Arguments:</span><br />
<a class="lnum" href="#1093" name="1093">1093</a><span class="string"></span><br />
<a class="lnum" href="#1094" name="1094">1094</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;hour,&#0160;minute&#0160;(required)</span><br />
<a class="lnum" href="#1095" name="1095">1095</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;second,&#0160;microsecond&#0160;(default&#0160;to&#0160;zero)</span><br />
<a class="lnum" href="#1096" name="1096">1096</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;tzinfo&#0160;(default&#0160;to&#0160;None)</span><br />
<a class="lnum" href="#1097" name="1097">1097</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1098" name="1098">1098</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span>&#0160;<span class="op">=</span>&#0160;<span class="name">object</span><span class="op">.</span><span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">)</span><br />
<a class="lnum" href="#1099" name="1099">1099</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">str</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1100" name="1100">1100</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support</span><br />
<a class="lnum" href="#1101" name="1101">1101</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__setstate</span><span class="op">(</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">None</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1102" name="1102">1102</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#1103" name="1103">1103</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzinfo_arg</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1104" name="1104">1104</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_time_fields</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1105" name="1105">1105</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">hour</span><br />
<a class="lnum" href="#1106" name="1106">1106</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">minute</span><br />
<a class="lnum" href="#1107" name="1107">1107</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">second</span><br />
<a class="lnum" href="#1108" name="1108">1108</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">microsecond</span><br />
<a class="lnum" href="#1109" name="1109">1109</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tzinfo</span><br />
<a class="lnum" href="#1110" name="1110">1110</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#1111" name="1111">1111</a><br />
<a class="lnum" href="#1112" name="1112">1112</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Read-only&#0160;field&#0160;accessors</span><br />
<a class="lnum" href="#1113" name="1113">1113</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"hour&#0160;(0-23)"</span><span class="op">)</span><br />
<a class="lnum" href="#1114" name="1114">1114</a>&#0160;&#0160;&#0160;&#0160;<span class="name">minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"minute&#0160;(0-59)"</span><span class="op">)</span><br />
<a class="lnum" href="#1115" name="1115">1115</a>&#0160;&#0160;&#0160;&#0160;<span class="name">second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"second&#0160;(0-59)"</span><span class="op">)</span><br />
<a class="lnum" href="#1116" name="1116">1116</a>&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">,</span><br />
<a class="lnum" href="#1117" name="1117">1117</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"microsecond&#0160;(0-999999)"</span><span class="op">)</span><br />
<a class="lnum" href="#1118" name="1118">1118</a>&#0160;&#0160;&#0160;&#0160;<span class="name">tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"timezone&#0160;info&#0160;object"</span><span class="op">)</span><br />
<a class="lnum" href="#1119" name="1119">1119</a><br />
<a class="lnum" href="#1120" name="1120">1120</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Standard&#0160;conversions,&#0160;__hash__&#0160;(and&#0160;helpers)</span><br />
<a class="lnum" href="#1121" name="1121">1121</a><span class="comment"></span><br />
<a class="lnum" href="#1122" name="1122">1122</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Comparisons.</span><br />
<a class="lnum" href="#1123" name="1123">1123</a><span class="comment"></span><br />
<a class="lnum" href="#1124" name="1124">1124</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__eq__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1125" name="1125">1125</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1126" name="1126">1126</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1127" name="1127">1127</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1128" name="1128">1128</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">False</span><br />
<a class="lnum" href="#1129" name="1129">1129</a><br />
<a class="lnum" href="#1130" name="1130">1130</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ne__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1131" name="1131">1131</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1132" name="1132">1132</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1133" name="1133">1133</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1134" name="1134">1134</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">True</span><br />
<a class="lnum" href="#1135" name="1135">1135</a><br />
<a class="lnum" href="#1136" name="1136">1136</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__le__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1137" name="1137">1137</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1138" name="1138">1138</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1139" name="1139">1139</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1140" name="1140">1140</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1141" name="1141">1141</a><br />
<a class="lnum" href="#1142" name="1142">1142</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__lt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1143" name="1143">1143</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1144" name="1144">1144</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1145" name="1145">1145</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1146" name="1146">1146</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1147" name="1147">1147</a><br />
<a class="lnum" href="#1148" name="1148">1148</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ge__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1149" name="1149">1149</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1150" name="1150">1150</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1151" name="1151">1151</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1152" name="1152">1152</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1153" name="1153">1153</a><br />
<a class="lnum" href="#1154" name="1154">1154</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__gt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1155" name="1155">1155</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1156" name="1156">1156</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1157" name="1157">1157</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1158" name="1158">1158</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1159" name="1159">1159</a><br />
<a class="lnum" href="#1160" name="1160">1160</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__cmp</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1161" name="1161">1161</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><br />
<a class="lnum" href="#1162" name="1162">1162</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">mytz</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><br />
<a class="lnum" href="#1163" name="1163">1163</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">ottz</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">_tzinfo</span><br />
<a class="lnum" href="#1164" name="1164">1164</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">otoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#1165" name="1165">1165</a><br />
<a class="lnum" href="#1166" name="1166">1166</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">mytz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">ottz</span><span class="op">:</span><br />
<a class="lnum" href="#1167" name="1167">1167</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">base_compare</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span><br />
<a class="lnum" href="#1168" name="1168">1168</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1169" name="1169">1169</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1170" name="1170">1170</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">otoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1171" name="1171">1171</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">base_compare</span>&#0160;<span class="op">=</span>&#0160;<span class="name">myoff</span>&#0160;<span class="op">==</span>&#0160;<span class="name">otoff</span><br />
<a class="lnum" href="#1172" name="1172">1172</a><br />
<a class="lnum" href="#1173" name="1173">1173</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">base_compare</span><span class="op">:</span><br />
<a class="lnum" href="#1174" name="1174">1174</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cmp</span><span class="op">(</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1175" name="1175">1175</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">,</span><br />
<a class="lnum" href="#1176" name="1176">1176</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">(</span><span class="name">other</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1177" name="1177">1177</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1178" name="1178">1178</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">myoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">otoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1179" name="1179">1179</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;Buggy&#0160;in&#0160;2.2.2.</span><br />
<a class="lnum" href="#1180" name="1180">1180</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"cannot&#0160;compare&#0160;naive&#0160;and&#0160;aware&#0160;times"</span><span class="op">)</span><br />
<a class="lnum" href="#1181" name="1181">1181</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myhhmm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span>&#0160;<span class="op">-</span>&#0160;<span class="name">myoff</span><br />
<a class="lnum" href="#1182" name="1182">1182</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">othhmm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__minute</span>&#0160;<span class="op">-</span>&#0160;<span class="name">otoff</span><br />
<a class="lnum" href="#1183" name="1183">1183</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cmp</span><span class="op">(</span><span class="op">(</span><span class="name">myhhmm</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">,</span><br />
<a class="lnum" href="#1184" name="1184">1184</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">(</span><span class="name">othhmm</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1185" name="1185">1185</a><br />
<a class="lnum" href="#1186" name="1186">1186</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__hash__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1187" name="1187">1187</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Hash."""</span><br />
<a class="lnum" href="#1188" name="1188">1188</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tzoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1189" name="1189">1189</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">tzoff</span><span class="op">:</span>&#0160;<span class="comment">#&#0160;zero&#0160;or&#0160;None</span><br />
<a class="lnum" href="#1190" name="1190">1190</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">[</span><span class="number">0</span><span class="op">]</span><span class="op">)</span><br />
<a class="lnum" href="#1191" name="1191">1191</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">h</span><span class="op">,</span>&#0160;<span class="name">m</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span>&#0160;<span class="op">-</span>&#0160;<span class="name">tzoff</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#1192" name="1192">1192</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">h</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">24</span><span class="op">:</span><br />
<a class="lnum" href="#1193" name="1193">1193</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="name">time</span><span class="op">(</span><span class="name">h</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1194" name="1194">1194</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="op">(</span><span class="name">h</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1195" name="1195">1195</a><br />
<a class="lnum" href="#1196" name="1196">1196</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Conversion&#0160;to&#0160;string</span><br />
<a class="lnum" href="#1197" name="1197">1197</a><span class="comment"></span><br />
<a class="lnum" href="#1198" name="1198">1198</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">_tzstr</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">sep</span><span class="op">=</span><span class="string">":"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1199" name="1199">1199</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;formatted&#0160;timezone&#0160;offset&#0160;(+xx:xx)&#0160;or&#0160;None."""</span><br />
<a class="lnum" href="#1200" name="1200">1200</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">off</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1201" name="1201">1201</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">off</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1202" name="1202">1202</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">off</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#1203" name="1203">1203</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sign</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"-"</span><br />
<a class="lnum" href="#1204" name="1204">1204</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">off</span>&#0160;<span class="op">=</span>&#0160;<span class="op">-</span><span class="name">off</span><br />
<a class="lnum" href="#1205" name="1205">1205</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1206" name="1206">1206</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sign</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"+"</span><br />
<a class="lnum" href="#1207" name="1207">1207</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">off</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#1208" name="1208">1208</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="number">0</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">hh</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">24</span><br />
<a class="lnum" href="#1209" name="1209">1209</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">off</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"%s%02d%s%02d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">sign</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">sep</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">)</span><br />
<a class="lnum" href="#1210" name="1210">1210</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">off</span><br />
<a class="lnum" href="#1211" name="1211">1211</a><br />
<a class="lnum" href="#1212" name="1212">1212</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__repr__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1213" name="1213">1213</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Convert&#0160;to&#0160;formal&#0160;string,&#0160;for&#0160;repr()."""</span><br />
<a class="lnum" href="#1214" name="1214">1214</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#1215" name="1215">1215</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="string">",&#0160;%d,&#0160;%d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1216" name="1216">1216</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#1217" name="1217">1217</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="string">",&#0160;%d"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><br />
<a class="lnum" href="#1218" name="1218">1218</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1219" name="1219">1219</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="string">""</span><br />
<a class="lnum" href="#1220" name="1220">1220</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span><span class="op">=</span>&#0160;<span class="string">"%s(%d,&#0160;%d%s)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="string">'datetime.'</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span><br />
<a class="lnum" href="#1221" name="1221">1221</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">s</span><span class="op">)</span><br />
<a class="lnum" href="#1222" name="1222">1222</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1223" name="1223">1223</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">s</span><span class="op">[</span><span class="op">-</span><span class="number">1</span><span class="op">:</span><span class="op">]</span>&#0160;<span class="op">==</span>&#0160;<span class="string">")"</span><br />
<a class="lnum" href="#1224" name="1224">1224</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">s</span><span class="op">[</span><span class="op">:</span><span class="op">-</span><span class="number">1</span><span class="op">]</span>&#0160;<span class="op">+</span>&#0160;<span class="string">",&#0160;tzinfo=%r"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">+</span>&#0160;<span class="string">")"</span><br />
<a class="lnum" href="#1225" name="1225">1225</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#1226" name="1226">1226</a><br />
<a class="lnum" href="#1227" name="1227">1227</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">isoformat</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1228" name="1228">1228</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;time&#0160;formatted&#0160;according&#0160;to&#0160;ISO.</span><br />
<a class="lnum" href="#1229" name="1229">1229</a><span class="string"></span><br />
<a class="lnum" href="#1230" name="1230">1230</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;This&#0160;is&#0160;'HH:MM:SS.mmmmmm+zz:zz',&#0160;or&#0160;'HH:MM:SS+zz:zz'&#0160;if</span><br />
<a class="lnum" href="#1231" name="1231">1231</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;self.microsecond&#0160;==&#0160;0.</span><br />
<a class="lnum" href="#1232" name="1232">1232</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1233" name="1233">1233</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_format_time</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1234" name="1234">1234</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1235" name="1235">1235</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tz</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzstr</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1236" name="1236">1236</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tz</span><span class="op">:</span><br />
<a class="lnum" href="#1237" name="1237">1237</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">+=</span>&#0160;<span class="name">tz</span><br />
<a class="lnum" href="#1238" name="1238">1238</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#1239" name="1239">1239</a><br />
<a class="lnum" href="#1240" name="1240">1240</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__str__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">isoformat</span><br />
<a class="lnum" href="#1241" name="1241">1241</a><br />
<a class="lnum" href="#1242" name="1242">1242</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">strftime</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">fmt</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1243" name="1243">1243</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Format&#0160;using&#0160;strftime().&#0160;&#0160;The&#0160;date&#0160;part&#0160;of&#0160;the&#0160;timestamp&#0160;passed</span><br />
<a class="lnum" href="#1244" name="1244">1244</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;to&#0160;underlying&#0160;strftime&#0160;should&#0160;not&#0160;be&#0160;used.</span><br />
<a class="lnum" href="#1245" name="1245">1245</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1246" name="1246">1246</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;The&#0160;year&#0160;must&#0160;be&#0160;&gt;=&#0160;1900&#0160;else&#0160;Python's&#0160;strftime&#0160;implementation</span><br />
<a class="lnum" href="#1247" name="1247">1247</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;can&#0160;raise&#0160;a&#0160;bogus&#0160;exception.</span><br />
<a class="lnum" href="#1248" name="1248">1248</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">timetuple</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="number">1900</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span><br />
<a class="lnum" href="#1249" name="1249">1249</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1250" name="1250">1250</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="op">-</span><span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#1251" name="1251">1251</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_wrap_strftime</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">fmt</span><span class="op">,</span>&#0160;<span class="name">timetuple</span><span class="op">)</span><br />
<a class="lnum" href="#1252" name="1252">1252</a><br />
<a class="lnum" href="#1253" name="1253">1253</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Timezone&#0160;functions</span><br />
<a class="lnum" href="#1254" name="1254">1254</a><span class="comment"></span><br />
<a class="lnum" href="#1255" name="1255">1255</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">utcoffset</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1256" name="1256">1256</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;timezone&#0160;offset&#0160;in&#0160;minutes&#0160;east&#0160;of&#0160;UTC&#0160;(negative&#0160;west&#0160;of</span><br />
<a class="lnum" href="#1257" name="1257">1257</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;UTC)."""</span><br />
<a class="lnum" href="#1258" name="1258">1258</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1259" name="1259">1259</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1260" name="1260">1260</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1261" name="1261">1261</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">minutes</span><span class="op">=</span><span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1262" name="1262">1262</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1263" name="1263">1263</a><br />
<a class="lnum" href="#1264" name="1264">1264</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Return&#0160;an&#0160;integer&#0160;(or&#0160;None)&#0160;instead&#0160;of&#0160;a&#0160;timedelta&#0160;(or&#0160;None).</span><br />
<a class="lnum" href="#1265" name="1265">1265</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">_utcoffset</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1266" name="1266">1266</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1267" name="1267">1267</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1268" name="1268">1268</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1269" name="1269">1269</a><br />
<a class="lnum" href="#1270" name="1270">1270</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">tzname</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1271" name="1271">1271</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;timezone&#0160;name.</span><br />
<a class="lnum" href="#1272" name="1272">1272</a><span class="string"></span><br />
<a class="lnum" href="#1273" name="1273">1273</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;Note&#0160;that&#0160;the&#0160;name&#0160;is&#0160;100%&#0160;informational&#0160;--&#0160;there's&#0160;no&#0160;requirement&#0160;that</span><br />
<a class="lnum" href="#1274" name="1274">1274</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;it&#0160;mean&#0160;anything&#0160;in&#0160;particular.&#0160;For&#0160;example,&#0160;"GMT",&#0160;"UTC",&#0160;"-500",</span><br />
<a class="lnum" href="#1275" name="1275">1275</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"-5:00",&#0160;"EDT",&#0160;"US/Eastern",&#0160;"America/New&#0160;York"&#0160;are&#0160;all&#0160;valid&#0160;replies.</span><br />
<a class="lnum" href="#1276" name="1276">1276</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1277" name="1277">1277</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">name</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"tzname"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1278" name="1278">1278</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzname</span><span class="op">(</span><span class="name">name</span><span class="op">)</span><br />
<a class="lnum" href="#1279" name="1279">1279</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">name</span><br />
<a class="lnum" href="#1280" name="1280">1280</a><br />
<a class="lnum" href="#1281" name="1281">1281</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">dst</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1282" name="1282">1282</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;0&#0160;if&#0160;DST&#0160;is&#0160;not&#0160;in&#0160;effect,&#0160;or&#0160;the&#0160;DST&#0160;offset&#0160;(in&#0160;minutes</span><br />
<a class="lnum" href="#1283" name="1283">1283</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;eastward)&#0160;if&#0160;DST&#0160;is&#0160;in&#0160;effect.</span><br />
<a class="lnum" href="#1284" name="1284">1284</a><span class="string"></span><br />
<a class="lnum" href="#1285" name="1285">1285</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;This&#0160;is&#0160;purely&#0160;informational;&#0160;the&#0160;DST&#0160;offset&#0160;has&#0160;already&#0160;been&#0160;added&#0160;to</span><br />
<a class="lnum" href="#1286" name="1286">1286</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;the&#0160;UTC&#0160;offset&#0160;returned&#0160;by&#0160;utcoffset()&#0160;if&#0160;applicable,&#0160;so&#0160;there's&#0160;no</span><br />
<a class="lnum" href="#1287" name="1287">1287</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;need&#0160;to&#0160;consult&#0160;dst()&#0160;unless&#0160;you're&#0160;interested&#0160;in&#0160;displaying&#0160;the&#0160;DST</span><br />
<a class="lnum" href="#1288" name="1288">1288</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;info.</span><br />
<a class="lnum" href="#1289" name="1289">1289</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1290" name="1290">1290</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1291" name="1291">1291</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1292" name="1292">1292</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1293" name="1293">1293</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">minutes</span><span class="op">=</span><span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1294" name="1294">1294</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1295" name="1295">1295</a><br />
<a class="lnum" href="#1296" name="1296">1296</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">replace</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">=</span><span class="name">None</span><span class="op">,</span><br />
<a class="lnum" href="#1297" name="1297">1297</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tzinfo</span><span class="op">=</span><span class="name">True</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1298" name="1298">1298</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;a&#0160;new&#0160;time&#0160;with&#0160;new&#0160;values&#0160;for&#0160;the&#0160;specified&#0160;fields."""</span><br />
<a class="lnum" href="#1299" name="1299">1299</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">hour</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1300" name="1300">1300</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><br />
<a class="lnum" href="#1301" name="1301">1301</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">minute</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1302" name="1302">1302</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><br />
<a class="lnum" href="#1303" name="1303">1303</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">second</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1304" name="1304">1304</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><br />
<a class="lnum" href="#1305" name="1305">1305</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">microsecond</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1306" name="1306">1306</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><br />
<a class="lnum" href="#1307" name="1307">1307</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">True</span><span class="op">:</span><br />
<a class="lnum" href="#1308" name="1308">1308</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">tzinfo</span><br />
<a class="lnum" href="#1309" name="1309">1309</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_time_fields</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1310" name="1310">1310</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzinfo_arg</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1311" name="1311">1311</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1312" name="1312">1312</a><br />
<a class="lnum" href="#1313" name="1313">1313</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Return&#0160;an&#0160;integer&#0160;(or&#0160;None)&#0160;instead&#0160;of&#0160;a&#0160;timedelta&#0160;(or&#0160;None).</span><br />
<a class="lnum" href="#1314" name="1314">1314</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">_dst</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1315" name="1315">1315</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">None</span><span class="op">)</span><br />
<a class="lnum" href="#1316" name="1316">1316</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1317" name="1317">1317</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1318" name="1318">1318</a><br />
<a class="lnum" href="#1319" name="1319">1319</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__nonzero__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1320" name="1320">1320</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><span class="op">:</span><br />
<a class="lnum" href="#1321" name="1321">1321</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#1322" name="1322">1322</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span>&#0160;<span class="keyword">or</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1323" name="1323">1323</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span>&#0160;<span class="op">-</span>&#0160;<span class="name">offset</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1324" name="1324">1324</a><br />
<a class="lnum" href="#1325" name="1325">1325</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support.</span><br />
<a class="lnum" href="#1326" name="1326">1326</a><span class="comment"></span><br />
<a class="lnum" href="#1327" name="1327">1327</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__safe_for_unpickling__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;For&#0160;Python&#0160;2.2</span><br />
<a class="lnum" href="#1328" name="1328">1328</a><br />
<a class="lnum" href="#1329" name="1329">1329</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__getstate</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1330" name="1330">1330</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us2</span><span class="op">,</span>&#0160;<span class="name">us3</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">,</span>&#0160;<span class="number">256</span><span class="op">)</span><br />
<a class="lnum" href="#1331" name="1331">1331</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us1</span><span class="op">,</span>&#0160;<span class="name">us2</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">us2</span><span class="op">,</span>&#0160;<span class="number">256</span><span class="op">)</span><br />
<a class="lnum" href="#1332" name="1332">1332</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">basestate</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="string">"%c"</span>&#0160;<span class="op">*</span>&#0160;<span class="number">6</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1333" name="1333">1333</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us1</span><span class="op">,</span>&#0160;<span class="name">us2</span><span class="op">,</span>&#0160;<span class="name">us3</span><span class="op">)</span><br />
<a class="lnum" href="#1334" name="1334">1334</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1335" name="1335">1335</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">basestate</span><span class="op">,</span><span class="op">)</span><br />
<a class="lnum" href="#1336" name="1336">1336</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1337" name="1337">1337</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">basestate</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1338" name="1338">1338</a><br />
<a class="lnum" href="#1339" name="1339">1339</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__setstate</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">state</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1340" name="1340">1340</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">state</span><span class="op">,</span>&#0160;<span class="name">tuple</span><span class="op">)</span><br />
<a class="lnum" href="#1341" name="1341">1341</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">state</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">2</span><br />
<a class="lnum" href="#1342" name="1342">1342</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">string</span>&#0160;<span class="op">=</span>&#0160;<span class="name">state</span><span class="op">[</span><span class="number">0</span><span class="op">]</span><br />
<a class="lnum" href="#1343" name="1343">1343</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">string</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">6</span><br />
<a class="lnum" href="#1344" name="1344">1344</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">us1</span><span class="op">,</span>&#0160;<span class="name">us2</span><span class="op">,</span>&#0160;<span class="name">us3</span>&#0160;<span class="op">=</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">map</span><span class="op">(</span><span class="name">ord</span><span class="op">,</span>&#0160;<span class="name">string</span><span class="op">)</span><br />
<a class="lnum" href="#1346" name="1346">1346</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="op">(</span><span class="op">(</span><span class="name">us1</span>&#0160;<span class="op">&lt;&lt;</span>&#0160;<span class="number">8</span><span class="op">)</span>&#0160;<span class="op">|</span>&#0160;<span class="name">us2</span><span class="op">)</span>&#0160;<span class="op">&lt;&lt;</span>&#0160;<span class="number">8</span><span class="op">)</span>&#0160;<span class="op">|</span>&#0160;<span class="name">us3</span><br />
<a class="lnum" href="#1347" name="1347">1347</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">state</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">1</span><span class="op">:</span><br />
<a class="lnum" href="#1348" name="1348">1348</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#1349" name="1349">1349</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1350" name="1350">1350</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">state</span><span class="op">[</span><span class="number">1</span><span class="op">]</span><br />
<a class="lnum" href="#1351" name="1351">1351</a><br />
<a class="lnum" href="#1352" name="1352">1352</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__reduce__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1353" name="1353">1353</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">time</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1354" name="1354">1354</a><br />
<a class="lnum" href="#1355" name="1355">1355</a><span class="name">_time_class</span>&#0160;<span class="op">=</span>&#0160;<span class="name">time</span>&#0160;&#0160;<span class="comment">#&#0160;so&#0160;functions&#0160;w/&#0160;args&#0160;named&#0160;"time"&#0160;can&#0160;get&#0160;at&#0160;the&#0160;class</span><br />
<a class="lnum" href="#1356" name="1356">1356</a><br />
<a class="lnum" href="#1357" name="1357">1357</a><span class="name">time</span><span class="op">.</span><span class="name">min</span>&#0160;<span class="op">=</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="number">0</span><span class="op">,</span>&#0160;<span class="number">0</span><span class="op">)</span><br />
<a class="lnum" href="#1358" name="1358">1358</a><span class="name">time</span><span class="op">.</span><span class="name">max</span>&#0160;<span class="op">=</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="number">23</span><span class="op">,</span>&#0160;<span class="number">59</span><span class="op">,</span>&#0160;<span class="number">59</span><span class="op">,</span>&#0160;<span class="number">999999</span><span class="op">)</span><br />
<a class="lnum" href="#1359" name="1359">1359</a><span class="name">time</span><span class="op">.</span><span class="name">resolution</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">microseconds</span><span class="op">=</span><span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#1360" name="1360">1360</a><br />
<a class="lnum" href="#1361" name="1361">1361</a><span class="keyword">class</span>&#0160;<span class="name">datetime</span><span class="op">(</span><span class="name">date</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1362" name="1362">1362</a><br />
<a class="lnum" href="#1363" name="1363">1363</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;needs&#0160;docstrings</span><br />
<a class="lnum" href="#1364" name="1364">1364</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;See&#0160;http://www.zope.org/Members/fdrake/DateTimeWiki/TimeZoneInfo</span><br />
<a class="lnum" href="#1365" name="1365">1365</a><span class="comment"></span><br />
<a class="lnum" href="#1366" name="1366">1366</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">=</span><span class="number">0</span><span class="op">,</span><br />
<a class="lnum" href="#1367" name="1367">1367</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span><span class="op">=</span><span class="number">0</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">=</span><span class="name">None</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1368" name="1368">1368</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">str</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1369" name="1369">1369</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support</span><br />
<a class="lnum" href="#1370" name="1370">1370</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span>&#0160;<span class="op">=</span>&#0160;<span class="name">date</span><span class="op">.</span><span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">[</span><span class="op">:</span><span class="number">4</span><span class="op">]</span><span class="op">)</span><br />
<a class="lnum" href="#1371" name="1371">1371</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__setstate</span><span class="op">(</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1372" name="1372">1372</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#1373" name="1373">1373</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzinfo_arg</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1374" name="1374">1374</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_time_fields</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1375" name="1375">1375</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span>&#0160;<span class="op">=</span>&#0160;<span class="name">date</span><span class="op">.</span><span class="name">__new__</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#1376" name="1376">1376</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;This&#0160;duplicates&#0160;__year,&#0160;__month,&#0160;__day&#0160;for&#0160;convenience&#0160;:-(</span><br />
<a class="lnum" href="#1377" name="1377">1377</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">year</span><br />
<a class="lnum" href="#1378" name="1378">1378</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span>&#0160;<span class="op">=</span>&#0160;<span class="name">month</span><br />
<a class="lnum" href="#1379" name="1379">1379</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">day</span><br />
<a class="lnum" href="#1380" name="1380">1380</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">hour</span><br />
<a class="lnum" href="#1381" name="1381">1381</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">minute</span><br />
<a class="lnum" href="#1382" name="1382">1382</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">second</span><br />
<a class="lnum" href="#1383" name="1383">1383</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">microsecond</span><br />
<a class="lnum" href="#1384" name="1384">1384</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tzinfo</span><br />
<a class="lnum" href="#1385" name="1385">1385</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#1386" name="1386">1386</a><br />
<a class="lnum" href="#1387" name="1387">1387</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Read-only&#0160;field&#0160;accessors</span><br />
<a class="lnum" href="#1388" name="1388">1388</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"hour&#0160;(0-23)"</span><span class="op">)</span><br />
<a class="lnum" href="#1389" name="1389">1389</a>&#0160;&#0160;&#0160;&#0160;<span class="name">minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"minute&#0160;(0-59)"</span><span class="op">)</span><br />
<a class="lnum" href="#1390" name="1390">1390</a>&#0160;&#0160;&#0160;&#0160;<span class="name">second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"second&#0160;(0-59)"</span><span class="op">)</span><br />
<a class="lnum" href="#1391" name="1391">1391</a>&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">,</span><br />
<a class="lnum" href="#1392" name="1392">1392</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"microsecond&#0160;(0-999999)"</span><span class="op">)</span><br />
<a class="lnum" href="#1393" name="1393">1393</a>&#0160;&#0160;&#0160;&#0160;<span class="name">tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">property</span><span class="op">(</span><span class="keyword">lambda</span>&#0160;<span class="name">self</span><span class="op">:</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="name">doc</span><span class="op">=</span><span class="string">"timezone&#0160;info&#0160;object"</span><span class="op">)</span><br />
<a class="lnum" href="#1394" name="1394">1394</a><br />
<a class="lnum" href="#1395" name="1395">1395</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">fromtimestamp</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">,</span>&#0160;<span class="name">tz</span><span class="op">=</span><span class="name">None</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1396" name="1396">1396</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Construct&#0160;a&#0160;datetime&#0160;from&#0160;a&#0160;POSIX&#0160;timestamp&#0160;(like&#0160;time.time()).</span><br />
<a class="lnum" href="#1397" name="1397">1397</a><span class="string"></span><br />
<a class="lnum" href="#1398" name="1398">1398</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;A&#0160;timezone&#0160;info&#0160;object&#0160;may&#0160;be&#0160;passed&#0160;in&#0160;as&#0160;well.</span><br />
<a class="lnum" href="#1399" name="1399">1399</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1400" name="1400">1400</a><br />
<a class="lnum" href="#1401" name="1401">1401</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzinfo_arg</span><span class="op">(</span><span class="name">tz</span><span class="op">)</span><br />
<a class="lnum" href="#1402" name="1402">1402</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1403" name="1403">1403</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">converter</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">localtime</span><br />
<a class="lnum" href="#1404" name="1404">1404</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1405" name="1405">1405</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">converter</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">gmtime</span><br />
<a class="lnum" href="#1406" name="1406">1406</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">weekday</span><span class="op">,</span>&#0160;<span class="name">jday</span><span class="op">,</span>&#0160;<span class="name">dst</span>&#0160;<span class="op">=</span>&#0160;<span class="name">converter</span><span class="op">(</span><span class="name">t</span><span class="op">)</span><br />
<a class="lnum" href="#1407" name="1407">1407</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us</span>&#0160;<span class="op">=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="op">(</span><span class="name">t</span>&#0160;<span class="op">%</span>&#0160;<span class="number">1.0</span><span class="op">)</span>&#0160;<span class="op">*</span>&#0160;<span class="number">1000000</span><span class="op">)</span><br />
<a class="lnum" href="#1408" name="1408">1408</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">ss</span>&#0160;<span class="op">=</span>&#0160;<span class="name">min</span><span class="op">(</span><span class="name">ss</span><span class="op">,</span>&#0160;<span class="number">59</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;clamp&#0160;out&#0160;leap&#0160;seconds&#0160;if&#0160;the&#0160;platform&#0160;has&#0160;them</span><br />
<a class="lnum" href="#1409" name="1409">1409</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">result</span>&#0160;<span class="op">=</span>&#0160;<span class="name">cls</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">us</span><span class="op">,</span>&#0160;<span class="name">tz</span><span class="op">)</span><br />
<a class="lnum" href="#1410" name="1410">1410</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1411" name="1411">1411</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">result</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tz</span><span class="op">.</span><span class="name">fromutc</span><span class="op">(</span><span class="name">result</span><span class="op">)</span><br />
<a class="lnum" href="#1412" name="1412">1412</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">result</span><br />
<a class="lnum" href="#1413" name="1413">1413</a>&#0160;&#0160;&#0160;&#0160;<span class="name">fromtimestamp</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">fromtimestamp</span><span class="op">)</span><br />
<a class="lnum" href="#1414" name="1414">1414</a><br />
<a class="lnum" href="#1415" name="1415">1415</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">utcfromtimestamp</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1416" name="1416">1416</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Construct&#0160;a&#0160;UTC&#0160;datetime&#0160;from&#0160;a&#0160;POSIX&#0160;timestamp&#0160;(like&#0160;time.time())."</span><br />
<a class="lnum" href="#1417" name="1417">1417</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">weekday</span><span class="op">,</span>&#0160;<span class="name">jday</span><span class="op">,</span>&#0160;<span class="name">dst</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">gmtime</span><span class="op">(</span><span class="name">t</span><span class="op">)</span><br />
<a class="lnum" href="#1418" name="1418">1418</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us</span>&#0160;<span class="op">=</span>&#0160;<span class="name">int</span><span class="op">(</span><span class="op">(</span><span class="name">t</span>&#0160;<span class="op">%</span>&#0160;<span class="number">1.0</span><span class="op">)</span>&#0160;<span class="op">*</span>&#0160;<span class="number">1000000</span><span class="op">)</span><br />
<a class="lnum" href="#1419" name="1419">1419</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">ss</span>&#0160;<span class="op">=</span>&#0160;<span class="name">min</span><span class="op">(</span><span class="name">ss</span><span class="op">,</span>&#0160;<span class="number">59</span><span class="op">)</span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;clamp&#0160;out&#0160;leap&#0160;seconds&#0160;if&#0160;the&#0160;platform&#0160;has&#0160;them</span><br />
<a class="lnum" href="#1420" name="1420">1420</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="name">us</span><span class="op">)</span><br />
<a class="lnum" href="#1421" name="1421">1421</a>&#0160;&#0160;&#0160;&#0160;<span class="name">utcfromtimestamp</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">utcfromtimestamp</span><span class="op">)</span><br />
<a class="lnum" href="#1422" name="1422">1422</a><br />
<a class="lnum" href="#1423" name="1423">1423</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;This&#0160;is&#0160;supposed&#0160;to&#0160;do&#0160;better&#0160;than&#0160;we&#0160;*can*&#0160;do&#0160;by&#0160;using&#0160;time.time(),</span><br />
<a class="lnum" href="#1424" name="1424">1424</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;if&#0160;the&#0160;platform&#0160;supports&#0160;a&#0160;more&#0160;accurate&#0160;way.&#0160;&#0160;The&#0160;C&#0160;implementation</span><br />
<a class="lnum" href="#1425" name="1425">1425</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;uses&#0160;gettimeofday&#0160;on&#0160;platforms&#0160;that&#0160;have&#0160;it,&#0160;but&#0160;that&#0160;isn't</span><br />
<a class="lnum" href="#1426" name="1426">1426</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;available&#0160;from&#0160;Python.&#0160;&#0160;So&#0160;now()&#0160;may&#0160;return&#0160;different&#0160;results</span><br />
<a class="lnum" href="#1427" name="1427">1427</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;across&#0160;the&#0160;implementations.</span><br />
<a class="lnum" href="#1428" name="1428">1428</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">now</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">tz</span><span class="op">=</span><span class="name">None</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1429" name="1429">1429</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Construct&#0160;a&#0160;datetime&#0160;from&#0160;time.time()&#0160;and&#0160;optional&#0160;time&#0160;zone&#0160;info."</span><br />
<a class="lnum" href="#1430" name="1430">1430</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">time</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1431" name="1431">1431</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">.</span><span class="name">fromtimestamp</span><span class="op">(</span><span class="name">t</span><span class="op">,</span>&#0160;<span class="name">tz</span><span class="op">)</span><br />
<a class="lnum" href="#1432" name="1432">1432</a>&#0160;&#0160;&#0160;&#0160;<span class="name">now</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">now</span><span class="op">)</span><br />
<a class="lnum" href="#1433" name="1433">1433</a><br />
<a class="lnum" href="#1434" name="1434">1434</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">utcnow</span><span class="op">(</span><span class="name">cls</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1435" name="1435">1435</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Construct&#0160;a&#0160;UTC&#0160;datetime&#0160;from&#0160;time.time()."</span><br />
<a class="lnum" href="#1436" name="1436">1436</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_time</span><span class="op">.</span><span class="name">time</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1437" name="1437">1437</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">.</span><span class="name">utcfromtimestamp</span><span class="op">(</span><span class="name">t</span><span class="op">)</span><br />
<a class="lnum" href="#1438" name="1438">1438</a>&#0160;&#0160;&#0160;&#0160;<span class="name">utcnow</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">utcnow</span><span class="op">)</span><br />
<a class="lnum" href="#1439" name="1439">1439</a><br />
<a class="lnum" href="#1440" name="1440">1440</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">combine</span><span class="op">(</span><span class="name">cls</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1441" name="1441">1441</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Construct&#0160;a&#0160;datetime&#0160;from&#0160;a&#0160;given&#0160;date&#0160;and&#0160;a&#0160;given&#0160;time."</span><br />
<a class="lnum" href="#1442" name="1442">1442</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">date</span><span class="op">,</span>&#0160;<span class="name">_date_class</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1443" name="1443">1443</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"date&#0160;argument&#0160;must&#0160;be&#0160;a&#0160;date&#0160;instance"</span><span class="op">)</span><br />
<a class="lnum" href="#1444" name="1444">1444</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">time</span><span class="op">,</span>&#0160;<span class="name">_time_class</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1445" name="1445">1445</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"time&#0160;argument&#0160;must&#0160;be&#0160;a&#0160;time&#0160;instance"</span><span class="op">)</span><br />
<a class="lnum" href="#1446" name="1446">1446</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cls</span><span class="op">(</span><span class="name">date</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">date</span><span class="op">.</span><span class="name">day</span><span class="op">,</span><br />
<a class="lnum" href="#1447" name="1447">1447</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">time</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">.</span><span class="name">second</span><span class="op">,</span>&#0160;<span class="name">time</span><span class="op">.</span><span class="name">microsecond</span><span class="op">,</span><br />
<a class="lnum" href="#1448" name="1448">1448</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">time</span><span class="op">.</span><span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1449" name="1449">1449</a>&#0160;&#0160;&#0160;&#0160;<span class="name">combine</span>&#0160;<span class="op">=</span>&#0160;<span class="name">classmethod</span><span class="op">(</span><span class="name">combine</span><span class="op">)</span><br />
<a class="lnum" href="#1450" name="1450">1450</a><br />
<a class="lnum" href="#1451" name="1451">1451</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">timetuple</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1452" name="1452">1452</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;local&#0160;time&#0160;tuple&#0160;compatible&#0160;with&#0160;time.localtime()."</span><br />
<a class="lnum" href="#1453" name="1453">1453</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dst</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_dst</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1454" name="1454">1454</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">dst</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1455" name="1455">1455</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dst</span>&#0160;<span class="op">=</span>&#0160;<span class="op">-</span><span class="number">1</span><br />
<a class="lnum" href="#1456" name="1456">1456</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">dst</span><span class="op">:</span><br />
<a class="lnum" href="#1457" name="1457">1457</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dst</span>&#0160;<span class="op">=</span>&#0160;<span class="number">1</span><br />
<a class="lnum" href="#1458" name="1458">1458</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_build_struct_time</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span><span class="op">,</span><br />
<a class="lnum" href="#1459" name="1459">1459</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><span class="op">,</span><br />
<a class="lnum" href="#1460" name="1460">1460</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">dst</span><span class="op">)</span><br />
<a class="lnum" href="#1461" name="1461">1461</a><br />
<a class="lnum" href="#1462" name="1462">1462</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">utctimetuple</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1463" name="1463">1463</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;UTC&#0160;time&#0160;tuple&#0160;compatible&#0160;with&#0160;time.gmtime()."</span><br />
<a class="lnum" href="#1464" name="1464">1464</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span><br />
<a class="lnum" href="#1465" name="1465">1465</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><br />
<a class="lnum" href="#1466" name="1466">1466</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1467" name="1467">1467</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span><span class="op">:</span>&#0160;&#0160;<span class="comment">#&#0160;neither&#0160;None&#0160;nor&#0160;0</span><br />
<a class="lnum" href="#1468" name="1468">1468</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tmxxx</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span>&#0160;<span class="op">-</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1469" name="1469">1469</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tm</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">tm</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">tm</span><span class="op">.</span><span class="name">day</span><br />
<a class="lnum" href="#1470" name="1470">1470</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tm</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">tm</span><span class="op">.</span><span class="name">minute</span><br />
<a class="lnum" href="#1471" name="1471">1471</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">_build_struct_time</span><span class="op">(</span><span class="name">y</span><span class="op">,</span>&#0160;<span class="name">m</span><span class="op">,</span>&#0160;<span class="name">d</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">,</span>&#0160;<span class="name">ss</span><span class="op">,</span>&#0160;<span class="number">0</span><span class="op">)</span><br />
<a class="lnum" href="#1472" name="1472">1472</a><br />
<a class="lnum" href="#1473" name="1473">1473</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1474" name="1474">1474</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;the&#0160;date&#0160;part."</span><br />
<a class="lnum" href="#1475" name="1475">1475</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">date</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">)</span><br />
<a class="lnum" href="#1476" name="1476">1476</a><br />
<a class="lnum" href="#1477" name="1477">1477</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1478" name="1478">1478</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;the&#0160;time&#0160;part,&#0160;with&#0160;tzinfo&#0160;None."</span><br />
<a class="lnum" href="#1479" name="1479">1479</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1480" name="1480">1480</a><br />
<a class="lnum" href="#1481" name="1481">1481</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">timetz</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1482" name="1482">1482</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Return&#0160;the&#0160;time&#0160;part,&#0160;with&#0160;same&#0160;tzinfo."</span><br />
<a class="lnum" href="#1483" name="1483">1483</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">time</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><span class="op">,</span><br />
<a class="lnum" href="#1484" name="1484">1484</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1485" name="1485">1485</a><br />
<a class="lnum" href="#1486" name="1486">1486</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">replace</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">year</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">=</span><span class="name">None</span><span class="op">,</span><br />
<a class="lnum" href="#1487" name="1487">1487</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">minute</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">=</span><span class="name">None</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">=</span><span class="name">True</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1488" name="1488">1488</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;a&#0160;new&#0160;datetime&#0160;with&#0160;new&#0160;values&#0160;for&#0160;the&#0160;specified&#0160;fields."""</span><br />
<a class="lnum" href="#1489" name="1489">1489</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">year</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1490" name="1490">1490</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">year</span><br />
<a class="lnum" href="#1491" name="1491">1491</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">month</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1492" name="1492">1492</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">month</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">month</span><br />
<a class="lnum" href="#1493" name="1493">1493</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">day</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1494" name="1494">1494</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">day</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span><br />
<a class="lnum" href="#1495" name="1495">1495</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">hour</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1496" name="1496">1496</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hour</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span><br />
<a class="lnum" href="#1497" name="1497">1497</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">minute</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1498" name="1498">1498</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">minute</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">minute</span><br />
<a class="lnum" href="#1499" name="1499">1499</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">second</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1500" name="1500">1500</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">second</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><br />
<a class="lnum" href="#1501" name="1501">1501</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">microsecond</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1502" name="1502">1502</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><br />
<a class="lnum" href="#1503" name="1503">1503</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">True</span><span class="op">:</span><br />
<a class="lnum" href="#1504" name="1504">1504</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">tzinfo</span><br />
<a class="lnum" href="#1505" name="1505">1505</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_date_fields</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#1506" name="1506">1506</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_time_fields</span><span class="op">(</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span>&#0160;<span class="name">microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1507" name="1507">1507</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzinfo_arg</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1508" name="1508">1508</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">datetime</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">month</span><span class="op">,</span>&#0160;<span class="name">day</span><span class="op">,</span>&#0160;<span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">second</span><span class="op">,</span><br />
<a class="lnum" href="#1509" name="1509">1509</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">microsecond</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1510" name="1510">1510</a><br />
<a class="lnum" href="#1511" name="1511">1511</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">astimezone</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">tz</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1512" name="1512">1512</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">tz</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1513" name="1513">1513</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"tz&#0160;argument&#0160;must&#0160;be&#0160;an&#0160;instance&#0160;of&#0160;tzinfo"</span><span class="op">)</span><br />
<a class="lnum" href="#1514" name="1514">1514</a><br />
<a class="lnum" href="#1515" name="1515">1515</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">mytz</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">tzinfo</span><br />
<a class="lnum" href="#1516" name="1516">1516</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">mytz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1517" name="1517">1517</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValueError</span><span class="op">(</span><span class="string">"astimezone()&#0160;requires&#0160;an&#0160;aware&#0160;datetime"</span><span class="op">)</span><br />
<a class="lnum" href="#1518" name="1518">1518</a><br />
<a class="lnum" href="#1519" name="1519">1519</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">mytz</span><span class="op">:</span><br />
<a class="lnum" href="#1520" name="1520">1520</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><br />
<a class="lnum" href="#1521" name="1521">1521</a><br />
<a class="lnum" href="#1522" name="1522">1522</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Convert&#0160;self&#0160;to&#0160;UTC,&#0160;and&#0160;attach&#0160;the&#0160;new&#0160;time&#0160;zone&#0160;object.</span><br />
<a class="lnum" href="#1523" name="1523">1523</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myoffset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1524" name="1524">1524</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">myoffset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1525" name="1525">1525</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">ValuError</span><span class="op">(</span><span class="string">"astimezone()&#0160;requires&#0160;an&#0160;aware&#0160;datetime"</span><span class="op">)</span><br />
<a class="lnum" href="#1526" name="1526">1526</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">utc</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="name">self</span>&#0160;<span class="op">-</span>&#0160;<span class="name">myoffset</span><span class="op">)</span><span class="op">.</span><span class="name">replace</span><span class="op">(</span><span class="name">tzinfo</span><span class="op">=</span><span class="name">tz</span><span class="op">)</span><br />
<a class="lnum" href="#1527" name="1527">1527</a><br />
<a class="lnum" href="#1528" name="1528">1528</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Convert&#0160;from&#0160;UTC&#0160;to&#0160;tz's&#0160;local&#0160;time.</span><br />
<a class="lnum" href="#1529" name="1529">1529</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">tz</span><span class="op">.</span><span class="name">fromutc</span><span class="op">(</span><span class="name">utc</span><span class="op">)</span><br />
<a class="lnum" href="#1530" name="1530">1530</a><br />
<a class="lnum" href="#1531" name="1531">1531</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Ways&#0160;to&#0160;produce&#0160;a&#0160;string.</span><br />
<a class="lnum" href="#1532" name="1532">1532</a><span class="comment"></span><br />
<a class="lnum" href="#1533" name="1533">1533</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">ctime</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1534" name="1534">1534</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Format&#0160;a&#0160;la&#0160;ctime()."</span><br />
<a class="lnum" href="#1535" name="1535">1535</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tmxxx</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span><br />
<a class="lnum" href="#1536" name="1536">1536</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">)</span><br />
<a class="lnum" href="#1537" name="1537">1537</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">ctime</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1538" name="1538">1538</a><br />
<a class="lnum" href="#1539" name="1539">1539</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">isoformat</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">sep</span><span class="op">=</span><span class="string">'T'</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1540" name="1540">1540</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;time&#0160;formatted&#0160;according&#0160;to&#0160;ISO.</span><br />
<a class="lnum" href="#1541" name="1541">1541</a><span class="string"></span><br />
<a class="lnum" href="#1542" name="1542">1542</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;This&#0160;is&#0160;'YYYY-MM-DD&#0160;HH:MM:SS.mmmmmm',&#0160;or&#0160;'YYYY-MM-DD&#0160;HH:MM:SS'&#0160;if</span><br />
<a class="lnum" href="#1543" name="1543">1543</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;self.microsecond&#0160;==&#0160;0.</span><br />
<a class="lnum" href="#1544" name="1544">1544</a><span class="string"></span><br />
<a class="lnum" href="#1545" name="1545">1545</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;If&#0160;self.tzinfo&#0160;is&#0160;not&#0160;None,&#0160;the&#0160;UTC&#0160;offset&#0160;is&#0160;also&#0160;attached,&#0160;giving</span><br />
<a class="lnum" href="#1546" name="1546">1546</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;'YYYY-MM-DD&#0160;HH:MM:SS.mmmmmm+HH:MM'&#0160;or&#0160;'YYYY-MM-DD&#0160;HH:MM:SS+HH:MM'.</span><br />
<a class="lnum" href="#1547" name="1547">1547</a><span class="string"></span><br />
<a class="lnum" href="#1548" name="1548">1548</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;Optional&#0160;argument&#0160;sep&#0160;specifies&#0160;the&#0160;separator&#0160;between&#0160;date&#0160;and</span><br />
<a class="lnum" href="#1549" name="1549">1549</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;time,&#0160;default&#0160;'T'.</span><br />
<a class="lnum" href="#1550" name="1550">1550</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1551" name="1551">1551</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="string">"%04d-%02d-%02d%c"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span><br />
<a class="lnum" href="#1552" name="1552">1552</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sep</span><span class="op">)</span>&#0160;<span class="op">+</span><br />
<a class="lnum" href="#1553" name="1553">1553</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_format_time</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1554" name="1554">1554</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1555" name="1555">1555</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">off</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1556" name="1556">1556</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">off</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1557" name="1557">1557</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">off</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#1558" name="1558">1558</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sign</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"-"</span><br />
<a class="lnum" href="#1559" name="1559">1559</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">off</span>&#0160;<span class="op">=</span>&#0160;<span class="op">-</span><span class="name">off</span><br />
<a class="lnum" href="#1560" name="1560">1560</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1561" name="1561">1561</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">sign</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"+"</span><br />
<a class="lnum" href="#1562" name="1562">1562</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">off</span><span class="op">,</span>&#0160;<span class="number">60</span><span class="op">)</span><br />
<a class="lnum" href="#1563" name="1563">1563</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">+=</span>&#0160;<span class="string">"%s%02d:%02d"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">sign</span><span class="op">,</span>&#0160;<span class="name">hh</span><span class="op">,</span>&#0160;<span class="name">mm</span><span class="op">)</span><br />
<a class="lnum" href="#1564" name="1564">1564</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#1565" name="1565">1565</a><br />
<a class="lnum" href="#1566" name="1566">1566</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__repr__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1567" name="1567">1567</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Convert&#0160;to&#0160;formal&#0160;string,&#0160;for&#0160;repr()."</span><br />
<a class="lnum" href="#1568" name="1568">1568</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">L</span>&#0160;<span class="op">=</span>&#0160;<span class="op">[</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span>&#0160;<span class="comment">#&#0160;These&#0160;are&#0160;never&#0160;zero</span><br />
<a class="lnum" href="#1569" name="1569">1569</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">]</span><br />
<a class="lnum" href="#1570" name="1570">1570</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">while</span>&#0160;<span class="name">L</span><span class="op">[</span><span class="op">-</span><span class="number">1</span><span class="op">]</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#1571" name="1571">1571</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">del</span>&#0160;<span class="name">L</span><span class="op">[</span><span class="op">-</span><span class="number">1</span><span class="op">]</span><br />
<a class="lnum" href="#1572" name="1572">1572</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="string">",&#0160;"</span><span class="op">.</span><span class="name">join</span><span class="op">(</span><span class="name">map</span><span class="op">(</span><span class="name">str</span><span class="op">,</span>&#0160;<span class="name">L</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1573" name="1573">1573</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="string">"%s(%s)"</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="string">'datetime.'</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">.</span><span class="name">__name__</span><span class="op">,</span>&#0160;<span class="name">s</span><span class="op">)</span><br />
<a class="lnum" href="#1574" name="1574">1574</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1575" name="1575">1575</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">s</span><span class="op">[</span><span class="op">-</span><span class="number">1</span><span class="op">:</span><span class="op">]</span>&#0160;<span class="op">==</span>&#0160;<span class="string">")"</span><br />
<a class="lnum" href="#1576" name="1576">1576</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">s</span>&#0160;<span class="op">=</span>&#0160;<span class="name">s</span><span class="op">[</span><span class="op">:</span><span class="op">-</span><span class="number">1</span><span class="op">]</span>&#0160;<span class="op">+</span>&#0160;<span class="string">",&#0160;tzinfo=%r"</span>&#0160;<span class="op">%</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">+</span>&#0160;<span class="string">")"</span><br />
<a class="lnum" href="#1577" name="1577">1577</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">s</span><br />
<a class="lnum" href="#1578" name="1578">1578</a><br />
<a class="lnum" href="#1579" name="1579">1579</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__str__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1580" name="1580">1580</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Convert&#0160;to&#0160;string,&#0160;for&#0160;str()."</span><br />
<a class="lnum" href="#1581" name="1581">1581</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">isoformat</span><span class="op">(</span><span class="name">sep</span><span class="op">=</span><span class="string">'&#0160;'</span><span class="op">)</span><br />
<a class="lnum" href="#1582" name="1582">1582</a><br />
<a class="lnum" href="#1583" name="1583">1583</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">utcoffset</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1584" name="1584">1584</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;timezone&#0160;offset&#0160;in&#0160;minutes&#0160;east&#0160;of&#0160;UTC&#0160;(negative&#0160;west&#0160;of</span><br />
<a class="lnum" href="#1585" name="1585">1585</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;UTC)."""</span><br />
<a class="lnum" href="#1586" name="1586">1586</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">)</span><br />
<a class="lnum" href="#1587" name="1587">1587</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1588" name="1588">1588</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1589" name="1589">1589</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">minutes</span><span class="op">=</span><span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1590" name="1590">1590</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1591" name="1591">1591</a><br />
<a class="lnum" href="#1592" name="1592">1592</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Return&#0160;an&#0160;integer&#0160;(or&#0160;None)&#0160;instead&#0160;of&#0160;a&#0160;timedelta&#0160;(or&#0160;None).</span><br />
<a class="lnum" href="#1593" name="1593">1593</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">_utcoffset</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1594" name="1594">1594</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">)</span><br />
<a class="lnum" href="#1595" name="1595">1595</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"utcoffset"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1596" name="1596">1596</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1597" name="1597">1597</a><br />
<a class="lnum" href="#1598" name="1598">1598</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">tzname</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1599" name="1599">1599</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;the&#0160;timezone&#0160;name.</span><br />
<a class="lnum" href="#1600" name="1600">1600</a><span class="string"></span><br />
<a class="lnum" href="#1601" name="1601">1601</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;Note&#0160;that&#0160;the&#0160;name&#0160;is&#0160;100%&#0160;informational&#0160;--&#0160;there's&#0160;no&#0160;requirement&#0160;that</span><br />
<a class="lnum" href="#1602" name="1602">1602</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;it&#0160;mean&#0160;anything&#0160;in&#0160;particular.&#0160;For&#0160;example,&#0160;"GMT",&#0160;"UTC",&#0160;"-500",</span><br />
<a class="lnum" href="#1603" name="1603">1603</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"-5:00",&#0160;"EDT",&#0160;"US/Eastern",&#0160;"America/New&#0160;York"&#0160;are&#0160;all&#0160;valid&#0160;replies.</span><br />
<a class="lnum" href="#1604" name="1604">1604</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1605" name="1605">1605</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">name</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"tzname"</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">)</span><br />
<a class="lnum" href="#1606" name="1606">1606</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_check_tzname</span><span class="op">(</span><span class="name">name</span><span class="op">)</span><br />
<a class="lnum" href="#1607" name="1607">1607</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">name</span><br />
<a class="lnum" href="#1608" name="1608">1608</a><br />
<a class="lnum" href="#1609" name="1609">1609</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">dst</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1610" name="1610">1610</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"""Return&#0160;0&#0160;if&#0160;DST&#0160;is&#0160;not&#0160;in&#0160;effect,&#0160;or&#0160;the&#0160;DST&#0160;offset&#0160;(in&#0160;minutes</span><br />
<a class="lnum" href="#1611" name="1611">1611</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;eastward)&#0160;if&#0160;DST&#0160;is&#0160;in&#0160;effect.</span><br />
<a class="lnum" href="#1612" name="1612">1612</a><span class="string"></span><br />
<a class="lnum" href="#1613" name="1613">1613</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;This&#0160;is&#0160;purely&#0160;informational;&#0160;the&#0160;DST&#0160;offset&#0160;has&#0160;already&#0160;been&#0160;added&#0160;to</span><br />
<a class="lnum" href="#1614" name="1614">1614</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;the&#0160;UTC&#0160;offset&#0160;returned&#0160;by&#0160;utcoffset()&#0160;if&#0160;applicable,&#0160;so&#0160;there's&#0160;no</span><br />
<a class="lnum" href="#1615" name="1615">1615</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;need&#0160;to&#0160;consult&#0160;dst()&#0160;unless&#0160;you're&#0160;interested&#0160;in&#0160;displaying&#0160;the&#0160;DST</span><br />
<a class="lnum" href="#1616" name="1616">1616</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;info.</span><br />
<a class="lnum" href="#1617" name="1617">1617</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;"""</span><br />
<a class="lnum" href="#1618" name="1618">1618</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">)</span><br />
<a class="lnum" href="#1619" name="1619">1619</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1620" name="1620">1620</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">offset</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1621" name="1621">1621</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">minutes</span><span class="op">=</span><span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1622" name="1622">1622</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1623" name="1623">1623</a><br />
<a class="lnum" href="#1624" name="1624">1624</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Return&#0160;an&#0160;integer&#0160;(or&#0160;None)&#0160;instead&#0160;of&#0160;a&#0160;timedelta&#0160;(or&#0160;None).1573</span><br />
<a class="lnum" href="#1625" name="1625">1625</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">_dst</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1626" name="1626">1626</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_call_tzinfo_method</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">,</span>&#0160;<span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">)</span><br />
<a class="lnum" href="#1627" name="1627">1627</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">offset</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_check_utc_offset</span><span class="op">(</span><span class="string">"dst"</span><span class="op">,</span>&#0160;<span class="name">offset</span><span class="op">)</span><br />
<a class="lnum" href="#1628" name="1628">1628</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">offset</span><br />
<a class="lnum" href="#1629" name="1629">1629</a><br />
<a class="lnum" href="#1630" name="1630">1630</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Comparisons.</span><br />
<a class="lnum" href="#1631" name="1631">1631</a><span class="comment"></span><br />
<a class="lnum" href="#1632" name="1632">1632</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__eq__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1633" name="1633">1633</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1634" name="1634">1634</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1635" name="1635">1635</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1636" name="1636">1636</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1637" name="1637">1637</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1638" name="1638">1638</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">False</span><br />
<a class="lnum" href="#1639" name="1639">1639</a><br />
<a class="lnum" href="#1640" name="1640">1640</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ne__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1641" name="1641">1641</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1642" name="1642">1642</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">!=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1643" name="1643">1643</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1644" name="1644">1644</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1645" name="1645">1645</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1646" name="1646">1646</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">True</span><br />
<a class="lnum" href="#1647" name="1647">1647</a><br />
<a class="lnum" href="#1648" name="1648">1648</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__le__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1649" name="1649">1649</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1650" name="1650">1650</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1651" name="1651">1651</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1652" name="1652">1652</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1653" name="1653">1653</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1654" name="1654">1654</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1655" name="1655">1655</a><br />
<a class="lnum" href="#1656" name="1656">1656</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__lt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1657" name="1657">1657</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1658" name="1658">1658</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1659" name="1659">1659</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1660" name="1660">1660</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1661" name="1661">1661</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1662" name="1662">1662</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1663" name="1663">1663</a><br />
<a class="lnum" href="#1664" name="1664">1664</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__ge__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1665" name="1665">1665</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1666" name="1666">1666</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;=</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1667" name="1667">1667</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1668" name="1668">1668</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1669" name="1669">1669</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1670" name="1670">1670</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1671" name="1671">1671</a><br />
<a class="lnum" href="#1672" name="1672">1672</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__gt__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1673" name="1673">1673</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1674" name="1674">1674</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__cmp</span><span class="op">(</span><span class="name">other</span><span class="op">)</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1675" name="1675">1675</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">elif</span>&#0160;<span class="name">hasattr</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="string">"timetuple"</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1676" name="1676">1676</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1677" name="1677">1677</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1678" name="1678">1678</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">_cmperror</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><br />
<a class="lnum" href="#1679" name="1679">1679</a><br />
<a class="lnum" href="#1680" name="1680">1680</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__cmp</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1681" name="1681">1681</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><br />
<a class="lnum" href="#1682" name="1682">1682</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">mytz</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><br />
<a class="lnum" href="#1683" name="1683">1683</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">ottz</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">_tzinfo</span><br />
<a class="lnum" href="#1684" name="1684">1684</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">otoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#1685" name="1685">1685</a><br />
<a class="lnum" href="#1686" name="1686">1686</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">mytz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">ottz</span><span class="op">:</span><br />
<a class="lnum" href="#1687" name="1687">1687</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">base_compare</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span><br />
<a class="lnum" href="#1688" name="1688">1688</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1689" name="1689">1689</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">mytz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1690" name="1690">1690</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1691" name="1691">1691</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">ottz</span>&#0160;<span class="keyword">is</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1692" name="1692">1692</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">otoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1693" name="1693">1693</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">base_compare</span>&#0160;<span class="op">=</span>&#0160;<span class="name">myoff</span>&#0160;<span class="op">==</span>&#0160;<span class="name">otoff</span><br />
<a class="lnum" href="#1694" name="1694">1694</a><br />
<a class="lnum" href="#1695" name="1695">1695</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">base_compare</span><span class="op">:</span><br />
<a class="lnum" href="#1696" name="1696">1696</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">cmp</span><span class="op">(</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span><br />
<a class="lnum" href="#1697" name="1697">1697</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1698" name="1698">1698</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">,</span><br />
<a class="lnum" href="#1699" name="1699">1699</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">(</span><span class="name">other</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span><br />
<a class="lnum" href="#1700" name="1700">1700</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1701" name="1701">1701</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1702" name="1702">1702</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">myoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">otoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1703" name="1703">1703</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;Buggy&#0160;in&#0160;2.2.2.</span><br />
<a class="lnum" href="#1704" name="1704">1704</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">(</span><span class="string">"cannot&#0160;compare&#0160;naive&#0160;and&#0160;aware&#0160;datetimes"</span><span class="op">)</span><br />
<a class="lnum" href="#1705" name="1705">1705</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;What&#0160;follows&#0160;could&#0160;be&#0160;done&#0160;more&#0160;efficiently...</span><br />
<a class="lnum" href="#1706" name="1706">1706</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">diff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span>&#0160;<span class="op">-</span>&#0160;<span class="name">other</span>&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;this&#0160;will&#0160;take&#0160;offsets&#0160;into&#0160;account</span><br />
<a class="lnum" href="#1707" name="1707">1707</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">diff</span><span class="op">.</span><span class="name">days</span>&#0160;<span class="op">&lt;</span>&#0160;<span class="number">0</span><span class="op">:</span><br />
<a class="lnum" href="#1708" name="1708">1708</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">-</span><span class="number">1</span><br />
<a class="lnum" href="#1709" name="1709">1709</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">diff</span>&#0160;<span class="keyword">and</span>&#0160;<span class="number">1</span>&#0160;<span class="keyword">or</span>&#0160;<span class="number">0</span><br />
<a class="lnum" href="#1710" name="1710">1710</a><br />
<a class="lnum" href="#1711" name="1711">1711</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__add__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1712" name="1712">1712</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Add&#0160;a&#0160;datetime&#0160;and&#0160;a&#0160;timedelta."</span><br />
<a class="lnum" href="#1713" name="1713">1713</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1714" name="1714">1714</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1715" name="1715">1715</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span>&#0160;<span class="op">=</span>&#0160;<span class="name">tmxxx</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span><br />
<a class="lnum" href="#1716" name="1716">1716</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span><br />
<a class="lnum" href="#1717" name="1717">1717</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">days</span><span class="op">,</span><br />
<a class="lnum" href="#1718" name="1718">1718</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span><br />
<a class="lnum" href="#1719" name="1719">1719</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span><br />
<a class="lnum" href="#1720" name="1720">1720</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">seconds</span><span class="op">,</span><br />
<a class="lnum" href="#1721" name="1721">1721</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">microseconds</span><span class="op">)</span><br />
<a class="lnum" href="#1722" name="1722">1722</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_checkOverflow</span><span class="op">(</span><span class="name">t</span><span class="op">.</span><span class="name">year</span><span class="op">)</span><br />
<a class="lnum" href="#1723" name="1723">1723</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">result</span>&#0160;<span class="op">=</span>&#0160;<span class="name">datetime</span><span class="op">(</span><span class="name">t</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">day</span><span class="op">,</span><br />
<a class="lnum" href="#1724" name="1724">1724</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span><span class="op">.</span><span class="name">hour</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">minute</span><span class="op">,</span>&#0160;<span class="name">t</span><span class="op">.</span><span class="name">second</span><span class="op">,</span><br />
<a class="lnum" href="#1725" name="1725">1725</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">t</span><span class="op">.</span><span class="name">microsecond</span><span class="op">,</span>&#0160;<span class="name">tzinfo</span><span class="op">=</span><span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1726" name="1726">1726</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">result</span><br />
<a class="lnum" href="#1727" name="1727">1727</a><br />
<a class="lnum" href="#1728" name="1728">1728</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__radd__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">__add__</span><br />
<a class="lnum" href="#1729" name="1729">1729</a><br />
<a class="lnum" href="#1730" name="1730">1730</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__sub__</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">other</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1731" name="1731">1731</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="string">"Subtract&#0160;two&#0160;datetimes,&#0160;or&#0160;a&#0160;datetime&#0160;and&#0160;a&#0160;timedelta."</span><br />
<a class="lnum" href="#1732" name="1732">1732</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="keyword">not</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">datetime</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1733" name="1733">1733</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">other</span><span class="op">,</span>&#0160;<span class="name">timedelta</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1734" name="1734">1734</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">self</span>&#0160;<span class="op">+</span>&#0160;<span class="op">-</span><span class="name">other</span><br />
<a class="lnum" href="#1735" name="1735">1735</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">NotImplemented</span><br />
<a class="lnum" href="#1736" name="1736">1736</a><br />
<a class="lnum" href="#1737" name="1737">1737</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days1</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1738" name="1738">1738</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days2</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">toordinal</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1739" name="1739">1739</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">secs1</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#1740" name="1740">1740</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">secs2</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__second</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__minute</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span><br />
<a class="lnum" href="#1741" name="1741">1741</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">base</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">days1</span>&#0160;<span class="op">-</span>&#0160;<span class="name">days2</span><span class="op">,</span><br />
<a class="lnum" href="#1742" name="1742">1742</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">secs1</span>&#0160;<span class="op">-</span>&#0160;<span class="name">secs2</span><span class="op">,</span><br />
<a class="lnum" href="#1743" name="1743">1743</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">-</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">)</span><br />
<a class="lnum" href="#1744" name="1744">1744</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">:</span><br />
<a class="lnum" href="#1745" name="1745">1745</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">base</span><br />
<a class="lnum" href="#1746" name="1746">1746</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">myoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1747" name="1747">1747</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">otoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">other</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1748" name="1748">1748</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">myoff</span>&#0160;<span class="op">==</span>&#0160;<span class="name">otoff</span><span class="op">:</span><br />
<a class="lnum" href="#1749" name="1749">1749</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">base</span><br />
<a class="lnum" href="#1750" name="1750">1750</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">myoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span>&#0160;<span class="keyword">or</span>&#0160;<span class="name">otoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1751" name="1751">1751</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">raise</span>&#0160;<span class="name">TypeError</span><span class="op">,</span>&#0160;<span class="string">"cannot&#0160;mix&#0160;naive&#0160;and&#0160;timezone-aware&#0160;time"</span><br />
<a class="lnum" href="#1752" name="1752">1752</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">base</span>&#0160;<span class="op">+</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">minutes</span>&#0160;<span class="op">=</span>&#0160;<span class="name">otoff</span><span class="op">-</span><span class="name">myoff</span><span class="op">)</span><br />
<a class="lnum" href="#1753" name="1753">1753</a><br />
<a class="lnum" href="#1754" name="1754">1754</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__hash__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1755" name="1755">1755</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">tzoff</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_utcoffset</span><span class="op">(</span><span class="op">)</span><br />
<a class="lnum" href="#1756" name="1756">1756</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">tzoff</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1757" name="1757">1757</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">[</span><span class="number">0</span><span class="op">]</span><span class="op">)</span><br />
<a class="lnum" href="#1758" name="1758">1758</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">days</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">day</span><span class="op">)</span><br />
<a class="lnum" href="#1759" name="1759">1759</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">seconds</span>&#0160;<span class="op">=</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">hour</span>&#0160;<span class="op">*</span>&#0160;<span class="number">3600</span>&#0160;<span class="op">+</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">minute</span>&#0160;<span class="op">-</span>&#0160;<span class="name">tzoff</span><span class="op">)</span>&#0160;<span class="op">*</span>&#0160;<span class="number">60</span>&#0160;<span class="op">+</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">second</span><br />
<a class="lnum" href="#1760" name="1760">1760</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">hash</span><span class="op">(</span><span class="name">timedelta</span><span class="op">(</span><span class="name">days</span><span class="op">,</span>&#0160;<span class="name">seconds</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">microsecond</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1761" name="1761">1761</a><br />
<a class="lnum" href="#1762" name="1762">1762</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Pickle&#0160;support.</span><br />
<a class="lnum" href="#1763" name="1763">1763</a><span class="comment"></span><br />
<a class="lnum" href="#1764" name="1764">1764</a>&#0160;&#0160;&#0160;&#0160;<span class="name">__safe_for_unpickling__</span>&#0160;<span class="op">=</span>&#0160;<span class="name">True</span>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;For&#0160;Python&#0160;2.2</span><br />
<a class="lnum" href="#1765" name="1765">1765</a><br />
<a class="lnum" href="#1766" name="1766">1766</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__getstate</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1767" name="1767">1767</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">yhi</span><span class="op">,</span>&#0160;<span class="name">ylo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__year</span><span class="op">,</span>&#0160;<span class="number">256</span><span class="op">)</span><br />
<a class="lnum" href="#1768" name="1768">1768</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us2</span><span class="op">,</span>&#0160;<span class="name">us3</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span><span class="op">,</span>&#0160;<span class="number">256</span><span class="op">)</span><br />
<a class="lnum" href="#1769" name="1769">1769</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us1</span><span class="op">,</span>&#0160;<span class="name">us2</span>&#0160;<span class="op">=</span>&#0160;<span class="name">divmod</span><span class="op">(</span><span class="name">us2</span><span class="op">,</span>&#0160;<span class="number">256</span><span class="op">)</span><br />
<a class="lnum" href="#1770" name="1770">1770</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">basestate</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="string">"%c"</span>&#0160;<span class="op">*</span>&#0160;<span class="number">10</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="op">(</span><span class="name">yhi</span><span class="op">,</span>&#0160;<span class="name">ylo</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span><br />
<a class="lnum" href="#1771" name="1771">1771</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span><br />
<a class="lnum" href="#1772" name="1772">1772</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">us1</span><span class="op">,</span>&#0160;<span class="name">us2</span><span class="op">,</span>&#0160;<span class="name">us3</span><span class="op">)</span><br />
<a class="lnum" href="#1773" name="1773">1773</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="keyword">is</span>&#0160;<span class="name">None</span><span class="op">:</span><br />
<a class="lnum" href="#1774" name="1774">1774</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">basestate</span><span class="op">,</span><span class="op">)</span><br />
<a class="lnum" href="#1775" name="1775">1775</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1776" name="1776">1776</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">basestate</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span><span class="op">)</span><br />
<a class="lnum" href="#1777" name="1777">1777</a><br />
<a class="lnum" href="#1778" name="1778">1778</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__setstate</span><span class="op">(</span><span class="name">self</span><span class="op">,</span>&#0160;<span class="name">state</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1779" name="1779">1779</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">isinstance</span><span class="op">(</span><span class="name">state</span><span class="op">,</span>&#0160;<span class="name">tuple</span><span class="op">)</span><br />
<a class="lnum" href="#1780" name="1780">1780</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="number">1</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">state</span><span class="op">)</span>&#0160;<span class="op">&lt;=</span>&#0160;<span class="number">2</span><br />
<a class="lnum" href="#1781" name="1781">1781</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">string</span>&#0160;<span class="op">=</span>&#0160;<span class="name">state</span><span class="op">[</span><span class="number">0</span><span class="op">]</span><br />
<a class="lnum" href="#1782" name="1782">1782</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">assert</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">string</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">10</span><br />
<a class="lnum" href="#1783" name="1783">1783</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="op">(</span><span class="name">yhi</span><span class="op">,</span>&#0160;<span class="name">ylo</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__month</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__day</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__hour</span><span class="op">,</span><br />
<a class="lnum" href="#1784" name="1784">1784</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__minute</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__second</span><span class="op">,</span>&#0160;<span class="name">us1</span><span class="op">,</span>&#0160;<span class="name">us2</span><span class="op">,</span>&#0160;<span class="name">us3</span><span class="op">)</span>&#0160;<span class="op">=</span>&#0160;<span class="name">map</span><span class="op">(</span><span class="name">ord</span><span class="op">,</span>&#0160;<span class="name">string</span><span class="op">)</span><br />
<a class="lnum" href="#1785" name="1785">1785</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__year</span>&#0160;<span class="op">=</span>&#0160;<span class="name">yhi</span>&#0160;<span class="op">*</span>&#0160;<span class="number">256</span>&#0160;<span class="op">+</span>&#0160;<span class="name">ylo</span><br />
<a class="lnum" href="#1786" name="1786">1786</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__microsecond</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="op">(</span><span class="op">(</span><span class="name">us1</span>&#0160;<span class="op">&lt;&lt;</span>&#0160;<span class="number">8</span><span class="op">)</span>&#0160;<span class="op">|</span>&#0160;<span class="name">us2</span><span class="op">)</span>&#0160;<span class="op">&lt;&lt;</span>&#0160;<span class="number">8</span><span class="op">)</span>&#0160;<span class="op">|</span>&#0160;<span class="name">us3</span><br />
<a class="lnum" href="#1787" name="1787">1787</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">len</span><span class="op">(</span><span class="name">state</span><span class="op">)</span>&#0160;<span class="op">==</span>&#0160;<span class="number">1</span><span class="op">:</span><br />
<a class="lnum" href="#1788" name="1788">1788</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">None</span><br />
<a class="lnum" href="#1789" name="1789">1789</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">else</span><span class="op">:</span><br />
<a class="lnum" href="#1790" name="1790">1790</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">self</span><span class="op">.</span><span class="name">_tzinfo</span>&#0160;<span class="op">=</span>&#0160;<span class="name">state</span><span class="op">[</span><span class="number">1</span><span class="op">]</span><br />
<a class="lnum" href="#1791" name="1791">1791</a><br />
<a class="lnum" href="#1792" name="1792">1792</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">def</span>&#0160;<span class="name">__reduce__</span><span class="op">(</span><span class="name">self</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1793" name="1793">1793</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="op">(</span><span class="name">self</span><span class="op">.</span><span class="name">__class__</span><span class="op">,</span>&#0160;<span class="name">self</span><span class="op">.</span><span class="name">__getstate</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><br />
<a class="lnum" href="#1794" name="1794">1794</a><br />
<a class="lnum" href="#1795" name="1795">1795</a><br />
<a class="lnum" href="#1796" name="1796">1796</a><span class="name">datetime</span><span class="op">.</span><span class="name">min</span>&#0160;<span class="op">=</span>&#0160;<span class="name">datetime</span><span class="op">(</span><span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#1797" name="1797">1797</a><span class="name">datetime</span><span class="op">.</span><span class="name">max</span>&#0160;<span class="op">=</span>&#0160;<span class="name">datetime</span><span class="op">(</span><span class="number">9999</span><span class="op">,</span>&#0160;<span class="number">12</span><span class="op">,</span>&#0160;<span class="number">31</span><span class="op">,</span>&#0160;<span class="number">23</span><span class="op">,</span>&#0160;<span class="number">59</span><span class="op">,</span>&#0160;<span class="number">59</span><span class="op">,</span>&#0160;<span class="number">999999</span><span class="op">)</span><br />
<a class="lnum" href="#1798" name="1798">1798</a><span class="name">datetime</span><span class="op">.</span><span class="name">resolution</span>&#0160;<span class="op">=</span>&#0160;<span class="name">timedelta</span><span class="op">(</span><span class="name">microseconds</span><span class="op">=</span><span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#1799" name="1799">1799</a><br />
<a class="lnum" href="#1800" name="1800">1800</a><br />
<a class="lnum" href="#1801" name="1801">1801</a><span class="keyword">def</span>&#0160;<span class="name">_isoweek1monday</span><span class="op">(</span><span class="name">year</span><span class="op">)</span><span class="op">:</span><br />
<a class="lnum" href="#1802" name="1802">1802</a>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;Helper&#0160;to&#0160;calculate&#0160;the&#0160;day&#0160;number&#0160;of&#0160;the&#0160;Monday&#0160;starting&#0160;week&#0160;1</span><br />
<a class="lnum" href="#1803" name="1803">1803</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="comment">#&#0160;XXX&#0160;This&#0160;could&#0160;be&#0160;done&#0160;more&#0160;efficiently</span><br />
<a class="lnum" href="#1804" name="1804">1804</a><span class="comment"></span>&#0160;&#0160;&#0160;&#0160;<span class="name">THURSDAY</span>&#0160;<span class="op">=</span>&#0160;<span class="number">3</span><br />
<a class="lnum" href="#1805" name="1805">1805</a>&#0160;&#0160;&#0160;&#0160;<span class="name">firstday</span>&#0160;<span class="op">=</span>&#0160;<span class="name">_ymd2ord</span><span class="op">(</span><span class="name">year</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">,</span>&#0160;<span class="number">1</span><span class="op">)</span><br />
<a class="lnum" href="#1806" name="1806">1806</a>&#0160;&#0160;&#0160;&#0160;<span class="name">firstweekday</span>&#0160;<span class="op">=</span>&#0160;<span class="op">(</span><span class="name">firstday</span>&#0160;<span class="op">+</span>&#0160;<span class="number">6</span><span class="op">)</span>&#0160;<span class="op">%</span>&#0160;<span class="number">7</span>&#0160;<span class="comment">#&#0160;See&#0160;weekday()&#0160;above</span><br />
<a class="lnum" href="#1807" name="1807">1807</a>&#0160;&#0160;&#0160;&#0160;<span class="name">week1monday</span>&#0160;<span class="op">=</span>&#0160;<span class="name">firstday</span>&#0160;<span class="op">-</span>&#0160;<span class="name">firstweekday</span><br />
<a class="lnum" href="#1808" name="1808">1808</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">if</span>&#0160;<span class="name">firstweekday</span>&#0160;<span class="op">&gt;</span>&#0160;<span class="name">THURSDAY</span><span class="op">:</span><br />
<a class="lnum" href="#1809" name="1809">1809</a>&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;<span class="name">week1monday</span>&#0160;<span class="op">+=</span>&#0160;<span class="number">7</span><br />
<a class="lnum" href="#1810" name="1810">1810</a>&#0160;&#0160;&#0160;&#0160;<span class="keyword">return</span>&#0160;<span class="name">week1monday</span><br />
<a class="lnum" href="#1811" name="1811">1811</a><br />
<a class="lnum" href="#1812" name="1812">1812</a><span class="string">"""</span><br />
<a class="lnum" href="#1813" name="1813">1813</a><span class="string">Some&#0160;time&#0160;zone&#0160;algebra.&#0160;&#0160;For&#0160;a&#0160;datetime&#0160;x,&#0160;let</span><br />
<a class="lnum" href="#1814" name="1814">1814</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.n&#0160;=&#0160;x&#0160;stripped&#0160;of&#0160;its&#0160;timezone&#0160;--&#0160;its&#0160;naive&#0160;time.</span><br />
<a class="lnum" href="#1815" name="1815">1815</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.o&#0160;=&#0160;x.utcoffset(),&#0160;and&#0160;assuming&#0160;that&#0160;doesn't&#0160;raise&#0160;an&#0160;exception&#0160;or</span><br />
<a class="lnum" href="#1816" name="1816">1816</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;return&#0160;None</span><br />
<a class="lnum" href="#1817" name="1817">1817</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.d&#0160;=&#0160;x.dst(),&#0160;and&#0160;assuming&#0160;that&#0160;doesn't&#0160;raise&#0160;an&#0160;exception&#0160;or</span><br />
<a class="lnum" href="#1818" name="1818">1818</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;return&#0160;None</span><br />
<a class="lnum" href="#1819" name="1819">1819</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.s&#0160;=&#0160;x's&#0160;standard&#0160;offset,&#0160;x.o&#0160;-&#0160;x.d</span><br />
<a class="lnum" href="#1820" name="1820">1820</a><span class="string"></span><br />
<a class="lnum" href="#1821" name="1821">1821</a><span class="string">Now&#0160;some&#0160;derived&#0160;rules,&#0160;where&#0160;k&#0160;is&#0160;a&#0160;duration&#0160;(timedelta).</span><br />
<a class="lnum" href="#1822" name="1822">1822</a><span class="string"></span><br />
<a class="lnum" href="#1823" name="1823">1823</a><span class="string">1.&#0160;x.o&#0160;=&#0160;x.s&#0160;+&#0160;x.d</span><br />
<a class="lnum" href="#1824" name="1824">1824</a><span class="string">&#0160;&#0160;&#0160;This&#0160;follows&#0160;from&#0160;the&#0160;definition&#0160;of&#0160;x.s.</span><br />
<a class="lnum" href="#1825" name="1825">1825</a><span class="string"></span><br />
<a class="lnum" href="#1826" name="1826">1826</a><span class="string">2.&#0160;If&#0160;x&#0160;and&#0160;y&#0160;have&#0160;the&#0160;same&#0160;tzinfo&#0160;member,&#0160;x.s&#0160;=&#0160;y.s.</span><br />
<a class="lnum" href="#1827" name="1827">1827</a><span class="string">&#0160;&#0160;&#0160;This&#0160;is&#0160;actually&#0160;a&#0160;requirement,&#0160;an&#0160;assumption&#0160;we&#0160;need&#0160;to&#0160;make&#0160;about</span><br />
<a class="lnum" href="#1828" name="1828">1828</a><span class="string">&#0160;&#0160;&#0160;sane&#0160;tzinfo&#0160;classes.</span><br />
<a class="lnum" href="#1829" name="1829">1829</a><span class="string"></span><br />
<a class="lnum" href="#1830" name="1830">1830</a><span class="string">3.&#0160;The&#0160;naive&#0160;UTC&#0160;time&#0160;corresponding&#0160;to&#0160;x&#0160;is&#0160;x.n&#0160;-&#0160;x.o.</span><br />
<a class="lnum" href="#1831" name="1831">1831</a><span class="string">&#0160;&#0160;&#0160;This&#0160;is&#0160;again&#0160;a&#0160;requirement&#0160;for&#0160;a&#0160;sane&#0160;tzinfo&#0160;class.</span><br />
<a class="lnum" href="#1832" name="1832">1832</a><span class="string"></span><br />
<a class="lnum" href="#1833" name="1833">1833</a><span class="string">4.&#0160;(x+k).s&#0160;=&#0160;x.s</span><br />
<a class="lnum" href="#1834" name="1834">1834</a><span class="string">&#0160;&#0160;&#0160;This&#0160;follows&#0160;from&#0160;#2,&#0160;and&#0160;that&#0160;datimetimetz+timedelta&#0160;preserves&#0160;tzinfo.</span><br />
<a class="lnum" href="#1835" name="1835">1835</a><span class="string"></span><br />
<a class="lnum" href="#1836" name="1836">1836</a><span class="string">5.&#0160;(x+k).n&#0160;=&#0160;x.n&#0160;+&#0160;k</span><br />
<a class="lnum" href="#1837" name="1837">1837</a><span class="string">&#0160;&#0160;&#0160;Again&#0160;follows&#0160;from&#0160;how&#0160;arithmetic&#0160;is&#0160;defined.</span><br />
<a class="lnum" href="#1838" name="1838">1838</a><span class="string"></span><br />
<a class="lnum" href="#1839" name="1839">1839</a><span class="string">Now&#0160;we&#0160;can&#0160;explain&#0160;tz.fromutc(x).&#0160;&#0160;Let's&#0160;assume&#0160;it's&#0160;an&#0160;interesting&#0160;case</span><br />
<a class="lnum" href="#1840" name="1840">1840</a><span class="string">(meaning&#0160;that&#0160;the&#0160;various&#0160;tzinfo&#0160;methods&#0160;exist,&#0160;and&#0160;don't&#0160;blow&#0160;up&#0160;or&#0160;return</span><br />
<a class="lnum" href="#1841" name="1841">1841</a><span class="string">None&#0160;when&#0160;called).</span><br />
<a class="lnum" href="#1842" name="1842">1842</a><span class="string"></span><br />
<a class="lnum" href="#1843" name="1843">1843</a><span class="string">The&#0160;function&#0160;wants&#0160;to&#0160;return&#0160;a&#0160;datetime&#0160;y&#0160;with&#0160;timezone&#0160;tz,&#0160;equivalent&#0160;to&#0160;x.</span><br />
<a class="lnum" href="#1844" name="1844">1844</a><span class="string">x&#0160;is&#0160;already&#0160;in&#0160;UTC.</span><br />
<a class="lnum" href="#1845" name="1845">1845</a><span class="string"></span><br />
<a class="lnum" href="#1846" name="1846">1846</a><span class="string">By&#0160;#3,&#0160;we&#0160;want</span><br />
<a class="lnum" href="#1847" name="1847">1847</a><span class="string"></span><br />
<a class="lnum" href="#1848" name="1848">1848</a><span class="string">&#0160;&#0160;&#0160;&#0160;y.n&#0160;-&#0160;y.o&#0160;=&#0160;x.n&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[1]</span><br />
<a class="lnum" href="#1849" name="1849">1849</a><span class="string"></span><br />
<a class="lnum" href="#1850" name="1850">1850</a><span class="string">The&#0160;algorithm&#0160;starts&#0160;by&#0160;attaching&#0160;tz&#0160;to&#0160;x.n,&#0160;and&#0160;calling&#0160;that&#0160;y.&#0160;&#0160;So</span><br />
<a class="lnum" href="#1851" name="1851">1851</a><span class="string">x.n&#0160;=&#0160;y.n&#0160;at&#0160;the&#0160;start.&#0160;&#0160;Then&#0160;it&#0160;wants&#0160;to&#0160;add&#0160;a&#0160;duration&#0160;k&#0160;to&#0160;y,&#0160;so&#0160;that&#0160;[1]</span><br />
<a class="lnum" href="#1852" name="1852">1852</a><span class="string">becomes&#0160;true;&#0160;in&#0160;effect,&#0160;we&#0160;want&#0160;to&#0160;solve&#0160;[2]&#0160;for&#0160;k:</span><br />
<a class="lnum" href="#1853" name="1853">1853</a><span class="string"></span><br />
<a class="lnum" href="#1854" name="1854">1854</a><span class="string">&#0160;&#0160;&#0160;(y+k).n&#0160;-&#0160;(y+k).o&#0160;=&#0160;x.n&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[2]</span><br />
<a class="lnum" href="#1855" name="1855">1855</a><span class="string"></span><br />
<a class="lnum" href="#1856" name="1856">1856</a><span class="string">By&#0160;#1,&#0160;this&#0160;is&#0160;the&#0160;same&#0160;as</span><br />
<a class="lnum" href="#1857" name="1857">1857</a><span class="string"></span><br />
<a class="lnum" href="#1858" name="1858">1858</a><span class="string">&#0160;&#0160;&#0160;(y+k).n&#0160;-&#0160;((y+k).s&#0160;+&#0160;(y+k).d)&#0160;=&#0160;x.n&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[3]</span><br />
<a class="lnum" href="#1859" name="1859">1859</a><span class="string"></span><br />
<a class="lnum" href="#1860" name="1860">1860</a><span class="string">By&#0160;#5,&#0160;(y+k).n&#0160;=&#0160;y.n&#0160;+&#0160;k,&#0160;which&#0160;equals&#0160;x.n&#0160;+&#0160;k&#0160;because&#0160;x.n=y.n&#0160;at&#0160;the&#0160;start.</span><br />
<a class="lnum" href="#1861" name="1861">1861</a><span class="string">Substituting&#0160;that&#0160;into&#0160;[3],</span><br />
<a class="lnum" href="#1862" name="1862">1862</a><span class="string"></span><br />
<a class="lnum" href="#1863" name="1863">1863</a><span class="string">&#0160;&#0160;&#0160;x.n&#0160;+&#0160;k&#0160;-&#0160;(y+k).s&#0160;-&#0160;(y+k).d&#0160;=&#0160;x.n;&#0160;the&#0160;x.n&#0160;terms&#0160;cancel,&#0160;leaving</span><br />
<a class="lnum" href="#1864" name="1864">1864</a><span class="string">&#0160;&#0160;&#0160;k&#0160;-&#0160;(y+k).s&#0160;-&#0160;(y+k).d&#0160;=&#0160;0;&#0160;rearranging,</span><br />
<a class="lnum" href="#1865" name="1865">1865</a><span class="string">&#0160;&#0160;&#0160;k&#0160;=&#0160;(y+k).s&#0160;-&#0160;(y+k).d;&#0160;by&#0160;#4,&#0160;(y+k).s&#0160;==&#0160;y.s,&#0160;so</span><br />
<a class="lnum" href="#1866" name="1866">1866</a><span class="string">&#0160;&#0160;&#0160;k&#0160;=&#0160;y.s&#0160;-&#0160;(y+k).d</span><br />
<a class="lnum" href="#1867" name="1867">1867</a><span class="string"></span><br />
<a class="lnum" href="#1868" name="1868">1868</a><span class="string">On&#0160;the&#0160;RHS,&#0160;(y+k).d&#0160;can't&#0160;be&#0160;computed&#0160;directly,&#0160;but&#0160;y.s&#0160;can&#0160;be,&#0160;and&#0160;we</span><br />
<a class="lnum" href="#1869" name="1869">1869</a><span class="string">approximate&#0160;k&#0160;by&#0160;ignoring&#0160;the&#0160;(y+k).d&#0160;term&#0160;at&#0160;first.&#0160;&#0160;Note&#0160;that&#0160;k&#0160;can't&#0160;be</span><br />
<a class="lnum" href="#1870" name="1870">1870</a><span class="string">very&#0160;large,&#0160;since&#0160;all&#0160;offset-returning&#0160;methods&#0160;return&#0160;a&#0160;duration&#0160;of&#0160;magnitude</span><br />
<a class="lnum" href="#1871" name="1871">1871</a><span class="string">less&#0160;than&#0160;24&#0160;hours.&#0160;&#0160;For&#0160;that&#0160;reason,&#0160;if&#0160;y&#0160;is&#0160;firmly&#0160;in&#0160;std&#0160;time,&#0160;(y+k).d&#0160;must</span><br />
<a class="lnum" href="#1872" name="1872">1872</a><span class="string">be&#0160;0,&#0160;so&#0160;ignoring&#0160;it&#0160;has&#0160;no&#0160;consequence&#0160;then.</span><br />
<a class="lnum" href="#1873" name="1873">1873</a><span class="string"></span><br />
<a class="lnum" href="#1874" name="1874">1874</a><span class="string">In&#0160;any&#0160;case,&#0160;the&#0160;new&#0160;value&#0160;is</span><br />
<a class="lnum" href="#1875" name="1875">1875</a><span class="string"></span><br />
<a class="lnum" href="#1876" name="1876">1876</a><span class="string">&#0160;&#0160;&#0160;&#0160;z&#0160;=&#0160;y&#0160;+&#0160;y.s&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[4]</span><br />
<a class="lnum" href="#1877" name="1877">1877</a><span class="string"></span><br />
<a class="lnum" href="#1878" name="1878">1878</a><span class="string">It's&#0160;helpful&#0160;to&#0160;step&#0160;back&#0160;at&#0160;look&#0160;at&#0160;[4]&#0160;from&#0160;a&#0160;higher&#0160;level:&#0160;&#0160;it's&#0160;simply</span><br />
<a class="lnum" href="#1879" name="1879">1879</a><span class="string">mapping&#0160;from&#0160;UTC&#0160;to&#0160;tz's&#0160;standard&#0160;time.</span><br />
<a class="lnum" href="#1880" name="1880">1880</a><span class="string"></span><br />
<a class="lnum" href="#1881" name="1881">1881</a><span class="string">At&#0160;this&#0160;point,&#0160;if</span><br />
<a class="lnum" href="#1882" name="1882">1882</a><span class="string"></span><br />
<a class="lnum" href="#1883" name="1883">1883</a><span class="string">&#0160;&#0160;&#0160;&#0160;z.n&#0160;-&#0160;z.o&#0160;=&#0160;x.n&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[5]</span><br />
<a class="lnum" href="#1884" name="1884">1884</a><span class="string"></span><br />
<a class="lnum" href="#1885" name="1885">1885</a><span class="string">we&#0160;have&#0160;an&#0160;equivalent&#0160;time,&#0160;and&#0160;are&#0160;almost&#0160;done.&#0160;&#0160;The&#0160;insecurity&#0160;here&#0160;is</span><br />
<a class="lnum" href="#1886" name="1886">1886</a><span class="string">at&#0160;the&#0160;start&#0160;of&#0160;daylight&#0160;time.&#0160;&#0160;Picture&#0160;US&#0160;Eastern&#0160;for&#0160;concreteness.&#0160;&#0160;The&#0160;wall</span><br />
<a class="lnum" href="#1887" name="1887">1887</a><span class="string">time&#0160;jumps&#0160;from&#0160;1:59&#0160;to&#0160;3:00,&#0160;and&#0160;wall&#0160;hours&#0160;of&#0160;the&#0160;form&#0160;2:MM&#0160;don't&#0160;make&#0160;good</span><br />
<a class="lnum" href="#1888" name="1888">1888</a><span class="string">sense&#0160;then.&#0160;&#0160;The&#0160;docs&#0160;ask&#0160;that&#0160;an&#0160;Eastern&#0160;tzinfo&#0160;class&#0160;consider&#0160;such&#0160;a&#0160;time&#0160;to</span><br />
<a class="lnum" href="#1889" name="1889">1889</a><span class="string">be&#0160;EDT&#0160;(because&#0160;it's&#0160;"after&#0160;2"),&#0160;which&#0160;is&#0160;a&#0160;redundant&#0160;spelling&#0160;of&#0160;1:MM&#0160;EST</span><br />
<a class="lnum" href="#1890" name="1890">1890</a><span class="string">on&#0160;the&#0160;day&#0160;DST&#0160;starts.&#0160;&#0160;We&#0160;want&#0160;to&#0160;return&#0160;the&#0160;1:MM&#0160;EST&#0160;spelling&#0160;because&#0160;that's</span><br />
<a class="lnum" href="#1891" name="1891">1891</a><span class="string">the&#0160;only&#0160;spelling&#0160;that&#0160;makes&#0160;sense&#0160;on&#0160;the&#0160;local&#0160;wall&#0160;clock.</span><br />
<a class="lnum" href="#1892" name="1892">1892</a><span class="string"></span><br />
<a class="lnum" href="#1893" name="1893">1893</a><span class="string">In&#0160;fact,&#0160;if&#0160;[5]&#0160;holds&#0160;at&#0160;this&#0160;point,&#0160;we&#0160;do&#0160;have&#0160;the&#0160;standard-time&#0160;spelling,</span><br />
<a class="lnum" href="#1894" name="1894">1894</a><span class="string">but&#0160;that&#0160;takes&#0160;a&#0160;bit&#0160;of&#0160;proof.&#0160;&#0160;We&#0160;first&#0160;prove&#0160;a&#0160;stronger&#0160;result.&#0160;&#0160;What's&#0160;the</span><br />
<a class="lnum" href="#1895" name="1895">1895</a><span class="string">difference&#0160;between&#0160;the&#0160;LHS&#0160;and&#0160;RHS&#0160;of&#0160;[5]?&#0160;&#0160;Let</span><br />
<a class="lnum" href="#1896" name="1896">1896</a><span class="string"></span><br />
<a class="lnum" href="#1897" name="1897">1897</a><span class="string">&#0160;&#0160;&#0160;&#0160;diff&#0160;=&#0160;x.n&#0160;-&#0160;(z.n&#0160;-&#0160;z.o)&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[6]</span><br />
<a class="lnum" href="#1898" name="1898">1898</a><span class="string"></span><br />
<a class="lnum" href="#1899" name="1899">1899</a><span class="string">Now</span><br />
<a class="lnum" href="#1900" name="1900">1900</a><span class="string">&#0160;&#0160;&#0160;&#0160;z.n&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;by&#0160;[4]</span><br />
<a class="lnum" href="#1901" name="1901">1901</a><span class="string">&#0160;&#0160;&#0160;&#0160;(y&#0160;+&#0160;y.s).n&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;by&#0160;#5</span><br />
<a class="lnum" href="#1902" name="1902">1902</a><span class="string">&#0160;&#0160;&#0160;&#0160;y.n&#0160;+&#0160;y.s&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;since&#0160;y.n&#0160;=&#0160;x.n</span><br />
<a class="lnum" href="#1903" name="1903">1903</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.n&#0160;+&#0160;y.s&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;since&#0160;z&#0160;and&#0160;y&#0160;are&#0160;have&#0160;the&#0160;same&#0160;tzinfo&#0160;member,</span><br />
<a class="lnum" href="#1904" name="1904">1904</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;y.s&#0160;=&#0160;z.s&#0160;by&#0160;#2</span><br />
<a class="lnum" href="#1905" name="1905">1905</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.n&#0160;+&#0160;z.s</span><br />
<a class="lnum" href="#1906" name="1906">1906</a><span class="string"></span><br />
<a class="lnum" href="#1907" name="1907">1907</a><span class="string">Plugging&#0160;that&#0160;back&#0160;into&#0160;[6]&#0160;gives</span><br />
<a class="lnum" href="#1908" name="1908">1908</a><span class="string"></span><br />
<a class="lnum" href="#1909" name="1909">1909</a><span class="string">&#0160;&#0160;&#0160;&#0160;diff&#0160;=</span><br />
<a class="lnum" href="#1910" name="1910">1910</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.n&#0160;-&#0160;((x.n&#0160;+&#0160;z.s)&#0160;-&#0160;z.o)&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;expanding</span><br />
<a class="lnum" href="#1911" name="1911">1911</a><span class="string">&#0160;&#0160;&#0160;&#0160;x.n&#0160;-&#0160;x.n&#0160;-&#0160;z.s&#0160;+&#0160;z.o&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;cancelling</span><br />
<a class="lnum" href="#1912" name="1912">1912</a><span class="string">&#0160;&#0160;&#0160;&#0160;-&#0160;z.s&#0160;+&#0160;z.o&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;by&#0160;#2</span><br />
<a class="lnum" href="#1913" name="1913">1913</a><span class="string">&#0160;&#0160;&#0160;&#0160;z.d</span><br />
<a class="lnum" href="#1914" name="1914">1914</a><span class="string"></span><br />
<a class="lnum" href="#1915" name="1915">1915</a><span class="string">So&#0160;diff&#0160;=&#0160;z.d.</span><br />
<a class="lnum" href="#1916" name="1916">1916</a><span class="string"></span><br />
<a class="lnum" href="#1917" name="1917">1917</a><span class="string">If&#0160;[5]&#0160;is&#0160;true&#0160;now,&#0160;diff&#0160;=&#0160;0,&#0160;so&#0160;z.d&#0160;=&#0160;0&#0160;too,&#0160;and&#0160;we&#0160;have&#0160;the&#0160;standard-time</span><br />
<a class="lnum" href="#1918" name="1918">1918</a><span class="string">spelling&#0160;we&#0160;wanted&#0160;in&#0160;the&#0160;endcase&#0160;described&#0160;above.&#0160;&#0160;We're&#0160;done.&#0160;&#0160;Contrarily,</span><br />
<a class="lnum" href="#1919" name="1919">1919</a><span class="string">if&#0160;z.d&#0160;=&#0160;0,&#0160;then&#0160;we&#0160;have&#0160;a&#0160;UTC&#0160;equivalent,&#0160;and&#0160;are&#0160;also&#0160;done.</span><br />
<a class="lnum" href="#1920" name="1920">1920</a><span class="string"></span><br />
<a class="lnum" href="#1921" name="1921">1921</a><span class="string">If&#0160;[5]&#0160;is&#0160;not&#0160;true&#0160;now,&#0160;diff&#0160;=&#0160;z.d&#0160;!=&#0160;0,&#0160;and&#0160;z.d&#0160;is&#0160;the&#0160;offset&#0160;we&#0160;need&#0160;to</span><br />
<a class="lnum" href="#1922" name="1922">1922</a><span class="string">add&#0160;to&#0160;z&#0160;(in&#0160;effect,&#0160;z&#0160;is&#0160;in&#0160;tz's&#0160;standard&#0160;time,&#0160;and&#0160;we&#0160;need&#0160;to&#0160;shift&#0160;the</span><br />
<a class="lnum" href="#1923" name="1923">1923</a><span class="string">local&#0160;clock&#0160;into&#0160;tz's&#0160;daylight&#0160;time).</span><br />
<a class="lnum" href="#1924" name="1924">1924</a><span class="string"></span><br />
<a class="lnum" href="#1925" name="1925">1925</a><span class="string">Let</span><br />
<a class="lnum" href="#1926" name="1926">1926</a><span class="string"></span><br />
<a class="lnum" href="#1927" name="1927">1927</a><span class="string">&#0160;&#0160;&#0160;&#0160;z'&#0160;=&#0160;z&#0160;+&#0160;z.d&#0160;=&#0160;z&#0160;+&#0160;diff&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[7]</span><br />
<a class="lnum" href="#1928" name="1928">1928</a><span class="string"></span><br />
<a class="lnum" href="#1929" name="1929">1929</a><span class="string">and&#0160;we&#0160;can&#0160;again&#0160;ask&#0160;whether</span><br />
<a class="lnum" href="#1930" name="1930">1930</a><span class="string"></span><br />
<a class="lnum" href="#1931" name="1931">1931</a><span class="string">&#0160;&#0160;&#0160;&#0160;z'.n&#0160;-&#0160;z'.o&#0160;=&#0160;x.n&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;[8]</span><br />
<a class="lnum" href="#1932" name="1932">1932</a><span class="string"></span><br />
<a class="lnum" href="#1933" name="1933">1933</a><span class="string">If&#0160;so,&#0160;we're&#0160;done.&#0160;&#0160;If&#0160;not,&#0160;the&#0160;tzinfo&#0160;class&#0160;is&#0160;insane,&#0160;according&#0160;to&#0160;the</span><br />
<a class="lnum" href="#1934" name="1934">1934</a><span class="string">assumptions&#0160;we've&#0160;made.&#0160;&#0160;This&#0160;also&#0160;requires&#0160;a&#0160;bit&#0160;of&#0160;proof.&#0160;&#0160;As&#0160;before,&#0160;let's</span><br />
<a class="lnum" href="#1935" name="1935">1935</a><span class="string">compute&#0160;the&#0160;difference&#0160;between&#0160;the&#0160;LHS&#0160;and&#0160;RHS&#0160;of&#0160;[8]&#0160;(and&#0160;skipping&#0160;some&#0160;of</span><br />
<a class="lnum" href="#1936" name="1936">1936</a><span class="string">the&#0160;justifications&#0160;for&#0160;the&#0160;kinds&#0160;of&#0160;substitutions&#0160;we've&#0160;done&#0160;several&#0160;times</span><br />
<a class="lnum" href="#1937" name="1937">1937</a><span class="string">already):</span><br />
<a class="lnum" href="#1938" name="1938">1938</a><span class="string"></span><br />
<a class="lnum" href="#1939" name="1939">1939</a><span class="string">&#0160;&#0160;&#0160;&#0160;diff'&#0160;=&#0160;x.n&#0160;-&#0160;(z'.n&#0160;-&#0160;z'.o)&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;replacing&#0160;z'.n&#0160;via&#0160;[7]</span><br />
<a class="lnum" href="#1940" name="1940">1940</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x.n&#0160;&#0160;-&#0160;(z.n&#0160;+&#0160;diff&#0160;-&#0160;z'.o)&#0160;=&#0160;&#0160;&#0160;&#0160;replacing&#0160;diff&#0160;via&#0160;[6]</span><br />
<a class="lnum" href="#1941" name="1941">1941</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x.n&#0160;-&#0160;(z.n&#0160;+&#0160;x.n&#0160;-&#0160;(z.n&#0160;-&#0160;z.o)&#0160;-&#0160;z'.o)&#0160;=</span><br />
<a class="lnum" href="#1942" name="1942">1942</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;x.n&#0160;-&#0160;z.n&#0160;-&#0160;x.n&#0160;+&#0160;z.n&#0160;-&#0160;z.o&#0160;+&#0160;z'.o&#0160;=&#0160;&#0160;&#0160;&#0160;cancel&#0160;x.n</span><br />
<a class="lnum" href="#1943" name="1943">1943</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-&#0160;z.n&#0160;+&#0160;z.n&#0160;-&#0160;z.o&#0160;+&#0160;z'.o&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;cancel&#0160;z.n</span><br />
<a class="lnum" href="#1944" name="1944">1944</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-&#0160;z.o&#0160;+&#0160;z'.o&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;#1&#0160;twice</span><br />
<a class="lnum" href="#1945" name="1945">1945</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;-z.s&#0160;-&#0160;z.d&#0160;+&#0160;z'.s&#0160;+&#0160;z'.d&#0160;=&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;z&#0160;and&#0160;z'&#0160;have&#0160;same&#0160;tzinfo</span><br />
<a class="lnum" href="#1946" name="1946">1946</a><span class="string">&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;&#0160;z'.d&#0160;-&#0160;z.d</span><br />
<a class="lnum" href="#1947" name="1947">1947</a><span class="string"></span><br />
<a class="lnum" href="#1948" name="1948">1948</a><span class="string">So&#0160;z'&#0160;is&#0160;UTC-equivalent&#0160;to&#0160;x&#0160;iff&#0160;z'.d&#0160;=&#0160;z.d&#0160;at&#0160;this&#0160;point.&#0160;&#0160;If&#0160;they&#0160;are&#0160;equal,</span><br />
<a class="lnum" href="#1949" name="1949">1949</a><span class="string">we've&#0160;found&#0160;the&#0160;UTC-equivalent&#0160;so&#0160;are&#0160;done.&#0160;&#0160;In&#0160;fact,&#0160;we&#0160;stop&#0160;with&#0160;[7]&#0160;and</span><br />
<a class="lnum" href="#1950" name="1950">1950</a><span class="string">return&#0160;z',&#0160;not&#0160;bothering&#0160;to&#0160;compute&#0160;z'.d.</span><br />
<a class="lnum" href="#1951" name="1951">1951</a><span class="string"></span><br />
<a class="lnum" href="#1952" name="1952">1952</a><span class="string">How&#0160;could&#0160;z.d&#0160;and&#0160;z'd&#0160;differ?&#0160;&#0160;z'&#0160;=&#0160;z&#0160;+&#0160;z.d&#0160;[7],&#0160;so&#0160;merely&#0160;moving&#0160;z'&#0160;by</span><br />
<a class="lnum" href="#1953" name="1953">1953</a><span class="string">a&#0160;dst()&#0160;offset,&#0160;and&#0160;starting&#0160;*from*&#0160;a&#0160;time&#0160;already&#0160;in&#0160;DST&#0160;(we&#0160;know&#0160;z.d&#0160;!=&#0160;0),</span><br />
<a class="lnum" href="#1954" name="1954">1954</a><span class="string">would&#0160;have&#0160;to&#0160;change&#0160;the&#0160;result&#0160;dst()&#0160;returns:&#0160;&#0160;we&#0160;start&#0160;in&#0160;DST,&#0160;and&#0160;moving</span><br />
<a class="lnum" href="#1955" name="1955">1955</a><span class="string">a&#0160;little&#0160;further&#0160;into&#0160;it&#0160;takes&#0160;us&#0160;out&#0160;of&#0160;DST.</span><br />
<a class="lnum" href="#1956" name="1956">1956</a><span class="string"></span><br />
<a class="lnum" href="#1957" name="1957">1957</a><span class="string">There&#0160;isn't&#0160;a&#0160;sane&#0160;case&#0160;where&#0160;this&#0160;can&#0160;happen.&#0160;&#0160;The&#0160;closest&#0160;it&#0160;gets&#0160;is&#0160;at</span><br />
<a class="lnum" href="#1958" name="1958">1958</a><span class="string">the&#0160;end&#0160;of&#0160;DST,&#0160;where&#0160;there's&#0160;an&#0160;hour&#0160;in&#0160;UTC&#0160;with&#0160;no&#0160;spelling&#0160;in&#0160;a&#0160;hybrid</span><br />
<a class="lnum" href="#1959" name="1959">1959</a><span class="string">tzinfo&#0160;class.&#0160;&#0160;In&#0160;US&#0160;Eastern,&#0160;that's&#0160;5:MM&#0160;UTC&#0160;=&#0160;0:MM&#0160;EST&#0160;=&#0160;1:MM&#0160;EDT.&#0160;&#0160;During</span><br />
<a class="lnum" href="#1960" name="1960">1960</a><span class="string">that&#0160;hour,&#0160;on&#0160;an&#0160;Eastern&#0160;clock&#0160;1:MM&#0160;is&#0160;taken&#0160;as&#0160;being&#0160;in&#0160;standard&#0160;time&#0160;(6:MM</span><br />
<a class="lnum" href="#1961" name="1961">1961</a><span class="string">UTC)&#0160;because&#0160;the&#0160;docs&#0160;insist&#0160;on&#0160;that,&#0160;but&#0160;0:MM&#0160;is&#0160;taken&#0160;as&#0160;being&#0160;in&#0160;daylight</span><br />
<a class="lnum" href="#1962" name="1962">1962</a><span class="string">time&#0160;(4:MM&#0160;UTC).&#0160;&#0160;There&#0160;is&#0160;no&#0160;local&#0160;time&#0160;mapping&#0160;to&#0160;5:MM&#0160;UTC.&#0160;&#0160;The&#0160;local</span><br />
<a class="lnum" href="#1963" name="1963">1963</a><span class="string">clock&#0160;jumps&#0160;from&#0160;1:59&#0160;back&#0160;to&#0160;1:00&#0160;again,&#0160;and&#0160;repeats&#0160;the&#0160;1:MM&#0160;hour&#0160;in</span><br />
<a class="lnum" href="#1964" name="1964">1964</a><span class="string">standard&#0160;time.&#0160;&#0160;Since&#0160;that's&#0160;what&#0160;the&#0160;local&#0160;clock&#0160;*does*,&#0160;we&#0160;want&#0160;to&#0160;map&#0160;both</span><br />
<a class="lnum" href="#1965" name="1965">1965</a><span class="string">UTC&#0160;hours&#0160;5:MM&#0160;and&#0160;6:MM&#0160;to&#0160;1:MM&#0160;Eastern.&#0160;&#0160;The&#0160;result&#0160;is&#0160;ambiguous</span><br />
<a class="lnum" href="#1966" name="1966">1966</a><span class="string">in&#0160;local&#0160;time,&#0160;but&#0160;so&#0160;it&#0160;goes&#0160;--&#0160;it's&#0160;the&#0160;way&#0160;the&#0160;local&#0160;clock&#0160;works.</span><br />
<a class="lnum" href="#1967" name="1967">1967</a><span class="string"></span><br />
<a class="lnum" href="#1968" name="1968">1968</a><span class="string">When&#0160;x&#0160;=&#0160;5:MM&#0160;UTC&#0160;is&#0160;the&#0160;input&#0160;to&#0160;this&#0160;algorithm,&#0160;x.o=0,&#0160;y.o=-5&#0160;and&#0160;y.d=0,</span><br />
<a class="lnum" href="#1969" name="1969">1969</a><span class="string">so&#0160;z=0:MM.&#0160;&#0160;z.d=60&#0160;(minutes)&#0160;then,&#0160;so&#0160;[5]&#0160;doesn't&#0160;hold&#0160;and&#0160;we&#0160;keep&#0160;going.</span><br />
<a class="lnum" href="#1970" name="1970">1970</a><span class="string">z'&#0160;=&#0160;z&#0160;+&#0160;z.d&#0160;=&#0160;1:MM&#0160;then,&#0160;and&#0160;z'.d=0,&#0160;and&#0160;z'.d&#0160;-&#0160;z.d&#0160;=&#0160;-60&#0160;!=&#0160;0&#0160;so&#0160;[8]</span><br />
<a class="lnum" href="#1971" name="1971">1971</a><span class="string">(correctly)&#0160;concludes&#0160;that&#0160;z'&#0160;is&#0160;not&#0160;UTC-equivalent&#0160;to&#0160;x.</span><br />
<a class="lnum" href="#1972" name="1972">1972</a><span class="string"></span><br />
<a class="lnum" href="#1973" name="1973">1973</a><span class="string">Because&#0160;we&#0160;know&#0160;z.d&#0160;said&#0160;z&#0160;was&#0160;in&#0160;daylight&#0160;time&#0160;(else&#0160;[5]&#0160;would&#0160;have&#0160;held&#0160;and</span><br />
<a class="lnum" href="#1974" name="1974">1974</a><span class="string">we&#0160;would&#0160;have&#0160;stopped&#0160;then),&#0160;and&#0160;we&#0160;know&#0160;z.d&#0160;!=&#0160;z'.d&#0160;(else&#0160;[8]&#0160;would&#0160;have&#0160;held</span><br />
<a class="lnum" href="#1975" name="1975">1975</a><span class="string">and&#0160;we&#0160;we&#0160;have&#0160;stopped&#0160;then),&#0160;and&#0160;there&#0160;are&#0160;only&#0160;2&#0160;possible&#0160;values&#0160;dst()&#0160;can</span><br />
<a class="lnum" href="#1976" name="1976">1976</a><span class="string">return&#0160;in&#0160;Eastern,&#0160;it&#0160;follows&#0160;that&#0160;z'.d&#0160;must&#0160;be&#0160;0&#0160;(which&#0160;it&#0160;is&#0160;in&#0160;the&#0160;example,</span><br />
<a class="lnum" href="#1977" name="1977">1977</a><span class="string">but&#0160;the&#0160;reasoning&#0160;doesn't&#0160;depend&#0160;on&#0160;the&#0160;example&#0160;--&#0160;it&#0160;depends&#0160;on&#0160;there&#0160;being</span><br />
<a class="lnum" href="#1978" name="1978">1978</a><span class="string">two&#0160;possible&#0160;dst()&#0160;outcomes,&#0160;one&#0160;zero&#0160;and&#0160;the&#0160;other&#0160;non-zero).&#0160;&#0160;Therefore</span><br />
<a class="lnum" href="#1979" name="1979">1979</a><span class="string">z'&#0160;must&#0160;be&#0160;in&#0160;standard&#0160;time,&#0160;and&#0160;is&#0160;the&#0160;spelling&#0160;we&#0160;want&#0160;in&#0160;this&#0160;case.</span><br />
<a class="lnum" href="#1980" name="1980">1980</a><span class="string"></span><br />
<a class="lnum" href="#1981" name="1981">1981</a><span class="string">Note&#0160;again&#0160;that&#0160;z'&#0160;is&#0160;not&#0160;UTC-equivalent&#0160;as&#0160;far&#0160;as&#0160;the&#0160;hybrid&#0160;tzinfo&#0160;class&#0160;is</span><br />
<a class="lnum" href="#1982" name="1982">1982</a><span class="string">concerned&#0160;(because&#0160;it&#0160;takes&#0160;z'&#0160;as&#0160;being&#0160;in&#0160;standard&#0160;time&#0160;rather&#0160;than&#0160;the</span><br />
<a class="lnum" href="#1983" name="1983">1983</a><span class="string">daylight&#0160;time&#0160;we&#0160;intend&#0160;here),&#0160;but&#0160;returning&#0160;it&#0160;gives&#0160;the&#0160;real-life&#0160;"local</span><br />
<a class="lnum" href="#1984" name="1984">1984</a><span class="string">clock&#0160;repeats&#0160;an&#0160;hour"&#0160;behavior&#0160;when&#0160;mapping&#0160;the&#0160;"unspellable"&#0160;UTC&#0160;hour&#0160;into</span><br />
<a class="lnum" href="#1985" name="1985">1985</a><span class="string">tz.</span><br />
<a class="lnum" href="#1986" name="1986">1986</a><span class="string"></span><br />
<a class="lnum" href="#1987" name="1987">1987</a><span class="string">When&#0160;the&#0160;input&#0160;is&#0160;6:MM,&#0160;z=1:MM&#0160;and&#0160;z.d=0,&#0160;and&#0160;we&#0160;stop&#0160;at&#0160;once,&#0160;again&#0160;with</span><br />
<a class="lnum" href="#1988" name="1988">1988</a><span class="string">the&#0160;1:MM&#0160;standard&#0160;time&#0160;spelling&#0160;we&#0160;want.</span><br />
<a class="lnum" href="#1989" name="1989">1989</a><span class="string"></span><br />
<a class="lnum" href="#1990" name="1990">1990</a><span class="string">So&#0160;how&#0160;can&#0160;this&#0160;break?&#0160;&#0160;One&#0160;of&#0160;the&#0160;assumptions&#0160;must&#0160;be&#0160;violated.&#0160;&#0160;Two</span><br />
<a class="lnum" href="#1991" name="1991">1991</a><span class="string">possibilities:</span><br />
<a class="lnum" href="#1992" name="1992">1992</a><span class="string"></span><br />
<a class="lnum" href="#1993" name="1993">1993</a><span class="string">1)&#0160;[2]&#0160;effectively&#0160;says&#0160;that&#0160;y.s&#0160;is&#0160;invariant&#0160;across&#0160;all&#0160;y&#0160;belong&#0160;to&#0160;a&#0160;given</span><br />
<a class="lnum" href="#1994" name="1994">1994</a><span class="string">&#0160;&#0160;&#0160;time&#0160;zone.&#0160;&#0160;This&#0160;isn't&#0160;true&#0160;if,&#0160;for&#0160;political&#0160;reasons&#0160;or&#0160;continental&#0160;drift,</span><br />
<a class="lnum" href="#1995" name="1995">1995</a><span class="string">&#0160;&#0160;&#0160;a&#0160;region&#0160;decides&#0160;to&#0160;change&#0160;its&#0160;base&#0160;offset&#0160;from&#0160;UTC.</span><br />
<a class="lnum" href="#1996" name="1996">1996</a><span class="string"></span><br />
<a class="lnum" href="#1997" name="1997">1997</a><span class="string">2)&#0160;There&#0160;may&#0160;be&#0160;versions&#0160;of&#0160;"double&#0160;daylight"&#0160;time&#0160;where&#0160;the&#0160;tail&#0160;end&#0160;of</span><br />
<a class="lnum" href="#1998" name="1998">1998</a><span class="string">&#0160;&#0160;&#0160;the&#0160;analysis&#0160;gives&#0160;up&#0160;a&#0160;step&#0160;too&#0160;early.&#0160;&#0160;I&#0160;haven't&#0160;thought&#0160;about&#0160;that</span><br />
<a class="lnum" href="#1999" name="1999">1999</a><span class="string">&#0160;&#0160;&#0160;enough&#0160;to&#0160;say.</span><br />
<a class="lnum" href="#2000" name="2000">2000</a><span class="string"></span><br />
<a class="lnum" href="#2001" name="2001">2001</a><span class="string">In&#0160;any&#0160;case,&#0160;it's&#0160;clear&#0160;that&#0160;the&#0160;default&#0160;fromutc()&#0160;is&#0160;strong&#0160;enough&#0160;to&#0160;handle</span><br />
<a class="lnum" href="#2002" name="2002">2002</a><span class="string">"almost&#0160;all"&#0160;time&#0160;zones:&#0160;&#0160;so&#0160;long&#0160;as&#0160;the&#0160;standard&#0160;offset&#0160;is&#0160;invariant,&#0160;it</span><br />
<a class="lnum" href="#2003" name="2003">2003</a><span class="string">doesn't&#0160;matter&#0160;if&#0160;daylight&#0160;time&#0160;transition&#0160;points&#0160;change&#0160;from&#0160;year&#0160;to&#0160;year,&#0160;or</span><br />
<a class="lnum" href="#2004" name="2004">2004</a><span class="string">if&#0160;daylight&#0160;time&#0160;is&#0160;skipped&#0160;in&#0160;some&#0160;years;&#0160;it&#0160;doesn't&#0160;matter&#0160;how&#0160;large&#0160;or</span><br />
<a class="lnum" href="#2005" name="2005">2005</a><span class="string">small&#0160;dst()&#0160;may&#0160;get&#0160;within&#0160;its&#0160;bounds;&#0160;and&#0160;it&#0160;doesn't&#0160;even&#0160;matter&#0160;if&#0160;some</span><br />
<a class="lnum" href="#2006" name="2006">2006</a><span class="string">perverse&#0160;time&#0160;zone&#0160;returns&#0160;a&#0160;negative&#0160;dst()).&#0160;&#0160;So&#0160;a&#0160;breaking&#0160;case&#0160;must&#0160;be</span><br />
<a class="lnum" href="#2007" name="2007">2007</a><span class="string">pretty&#0160;bizarre,&#0160;and&#0160;a&#0160;tzinfo&#0160;subclass&#0160;can&#0160;override&#0160;fromutc()&#0160;if&#0160;it&#0160;is.</span><br />
<a class="lnum" href="#2008" name="2008">2008</a><span class="string">"""</span></code></div></body></html>